關(guān)于“php_curl不是”的問(wèn)題,小編就整理了【2】個(gè)相關(guān)介紹“php_curl不是”的解答:
php之curl設(shè)置超時(shí)實(shí)例?PHP CURL超時(shí)設(shè)置分兩種,毫秒跟秒都是可以的。
curl普通秒級(jí)超時(shí):
$ch = curl_init();curl_setopt($ch, CURLOPT_URL,$url)
;curl_setopt($ch, CURLOPT_RETURNTRANSFER,1)
;curl_setopt($ch, CURLOPT_TIMEOUT,60)
; //只需要設(shè)置一個(gè)秒的數(shù)量就可以curl_setopt($ch, CURLOPT_HTTPHEADER, $headers)
;curl_setopt($ch, CURLOPT_USERAGENT, $defined_vars['HTTP_USER_AGENT'])
;curl普通秒級(jí)超時(shí)使用:
curl_setopt($ch, CURLOPT_TIMEOUT,60)
;curl如果需要進(jìn)行毫秒超時(shí),需要增加:curl_easy_setopt(curl, CURLOPT_NOSIGNAL,1L)
;//或者curl_setopt ( $ch, CURLOPT_NOSIGNAL,true)
;//支持毫秒級(jí)別超時(shí)設(shè)置
如何使用php中的curl方法向服務(wù)器發(fā)送post請(qǐng)求?用PHP向服務(wù)器發(fā)送HTTP的POST請(qǐng)求,代碼如下:
<?php/** * 發(fā)送post請(qǐng)求 * @param string $url 請(qǐng)求地址 * @param array $post_data post鍵值對(duì)數(shù)據(jù) * @return string */ function send_post($url, $post_data) { $postdata = http_build_query($post_data); $options = array( 'http' => array( 'method' => 'POST', 'header' => 'Content-type:application/x-www-form-urlencoded', 'content' => $postdata, 'timeout' => 15 * 60 // 超時(shí)時(shí)間(單位:s) ) ); $context = stream_context_create($options); $result = file_get_contents($url, false, $context); return $result; }
到此,以上就是小編對(duì)于“php_curl不是”的問(wèn)題就介紹到這了,希望介紹關(guān)于“php_curl不是”的【2】點(diǎn)解答對(duì)大家有用。