我打電話這樣的一個URL的作用:捲曲不是從PHP工作,但它的命令行
訪問通過瀏覽器URL我得到正確的結果。並使用與curl
命令行時一樣,它獲取正確的信息:
C:\>curl "http://localhost:9910/boxreload/check?name=alvaro&test=true" -i
HTTP/1.1 200 OK
Content-type: application/json; charset=UTF-8
Content-length: 203
Server: Restlet-Framework/2.3.3
Accept-ranges: bytes
Date: Fri, 22 Jan 2016 18:01:30 GMT
{"restul": "true"}
但隨着PHP這樣做,當它從來沒有來自curl_exec
和服務器的時間背出30秒後。
$stringData = http_build_query($data);
$url = sprintf("%s?%s", $url, $stringData);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json;',
'Content-Length: ' . strlen($stringData))
);
// $url is "'http://localhost:9910/boxreload/check?name=alvaro&test=true'"
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
//never comes back from this call (server times out)
$curl_response = curl_exec($curl);
if(curl_response === FALSE){
echo "error en CURL";
echo curl_error($curl);
}
curl_close($curl);
//never reaches this point
print_r($curl_response);
這是爲什麼?我做錯了什麼?
你'echo'什麼都沒有。你期望什麼? –
@u_mulder我的觀點是,服務器在'curl_exec'上超時......永遠不會回來。我沒有在這個例子中迴應任何事情,因爲這對我的問題沒有必要。 – Alvaro
嘗試添加'curl_setopt($ curl,CURLOPT_PORT,9910);' – Slam