我試圖從外部網站使用cURL
在PHP
中獲取數據,但不知何故,它無法正常工作。
我已檢出CURL
啓用phpinfo()
。它顯示cURL
已啓用PHP - CURL已啓用,但無法正常工作
但是,我的代碼不起作用。
<?php
if (! function_exists ('curl_version')) {
exit ("Enable cURL in PHP");
}
$ch = curl_init();
$timeout = 0; // 100; // set to zero for no timeout
$myHITurl = "http://www.google.com";
curl_setopt ($ch, CURLOPT_URL, $myHITurl);
curl_setopt ($ch, CURLOPT_HEADER, 0);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec ($ch);
if (curl_errno ($ch)) {
echo curl_error ($ch);
curl_close ($ch);
exit();
}
curl_close ($ch);
// dump output of api if you want during test
echo "$file_contents";
?>
它超時。
我沒有使用WAMP或XAMPP服務器。以上代碼直接在服務器上運行。 我不知道發生了什麼問題。先謝謝了。
你正在使用哪個操作系統? – WisdmLabs
該錯誤表明捲曲本身正在工作。這看起來像是運行腳本的主機上的防火牆問題。 –
@WisdmLabs服務器操作系統是'linux' –