Curl

PHP curl 壞了

  • April 21, 2016

撥打電話時,Curl 似乎掛起。這破壞了 wordpress/wp-admin 站點和用於 IP-SMS 的 twillio 幫助程序庫。

安裝 vsftpd 並創建新使用者後出現此問題。

測試 curl 的腳本:(來自Google)

function nxs_cURLTest($url, $msg, $testText){  
 $ch = curl_init(); 
 curl_setopt($ch, CURLOPT_URL, $url); 
 curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.73 Safari/537.36"); 
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
 curl_setopt($ch, CURLOPT_TIMEOUT, 10); 
 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
 $response = curl_exec($ch); 
 $errmsg = curl_error($ch); 
 $cInfo = curl_getinfo($ch); 
 curl_close($ch); 
 echo "Testing ... ".$url." - ".$cInfo['url']."<br />";
 if (stripos($response, $testText)!==false) 
   echo "....".$msg." - OK<br />"; 
 else 
 { 
   echo "....<b style='color:red;'>".$msg." - Problem</b><br /><pre>"; 
   print_r($errmsg); 
   print_r($cInfo); 
   print_r(htmlentities($response)); 
   echo "</pre>There is a problem with cURL. You need to contact your server admin or hosting provider.";
 }
}

 nxs_cURLTest("http://www.nextscripts.com/", "HTTPS to NXS", "Social Networks");
 nxs_cURLTest("http://www.google.com/intl/en/contact/", "HTTP to Google", "Mountain View, CA");
 nxs_cURLTest("https://www.google.com/intl/en/contact/", "HTTPS to Google", "Mountain View, CA");
 nxs_cURLTest("https://www.facebook.com/", "HTTPS to Facebook", 'id="facebook"');
 nxs_cURLTest("https://graph.facebook.com/", "HTTPS to API (Graph) Facebook", 'get');  
 nxs_cURLTest("https://www.linkedin.com/nhome/", "HTTPS to LinkedIn", 'rel="canonical" href="https://www.linkedin.com/');

輸出:

Testing ... http://www.nextscripts.com/ - http://www.nextscripts.com/
....HTTPS to NXS - OK
Testing ... http://www.google.com/intl/en/contact/ - http://www.google.com/intl/en/contact/
....HTTP to Google - OK
Testing ... https://www.google.com/intl/en/contact/ - https://www.google.com/intl/en/contact/
....HTTPS to Google - Problem
Failed to connect to www.google.com port 443: Connection timed outArray
(
   [url] => https://www.google.com/intl/en/contact/
   [content_type] => 
   [http_code] => 0
   [header_size] => 0
   [request_size] => 0
   [filetime] => -1
   [ssl_verify_result] => 0
   [redirect_count] => 0
   [total_time] => 5.003154
   [namelookup_time] => 0.004183
   [connect_time] => 0
   [pretransfer_time] => 0
   [size_upload] => 0
   [size_download] => 0
   [speed_download] => 0
   [speed_upload] => 0
   [download_content_length] => -1
   [upload_content_length] => -1
   [starttransfer_time] => 0
   [redirect_time] => 0
   [redirect_url] => 
   [primary_ip] => 
   [certinfo] => Array
       (
       )

   [primary_port] => 0
   [local_ip] => 
   [local_port] => 0
)
There is a problem with cURL. You need to contact your server admin or hosting provider.Testing ... https://www.facebook.com/ - https://www.facebook.com/
....HTTPS to Facebook - Problem
Failed to connect to www.facebook.com port 443: Connection timed outArray
(
   [url] => https://www.facebook.com/
   [content_type] => 
   [http_code] => 0
   [header_size] => 0
   [request_size] => 0
   [filetime] => -1
   [ssl_verify_result] => 0
   [redirect_count] => 0
   [total_time] => 5.003227
   [namelookup_time] => 0.004192
   [connect_time] => 0
   [pretransfer_time] => 0
   [size_upload] => 0
   [size_download] => 0
   [speed_download] => 0
   [speed_upload] => 0
   [download_content_length] => -1
   [upload_content_length] => -1
   [starttransfer_time] => 0
   [redirect_time] => 0
   [redirect_url] => 
   [primary_ip] => 
   [certinfo] => Array
       (
       )

   [primary_port] => 0
   [local_ip] => 
   [local_port] => 0
)
There is a problem with cURL. You need to contact your server admin or hosting provider.Testing ... https://graph.facebook.com/ - https://graph.facebook.com/
....HTTPS to API (Graph) Facebook - Problem
Failed to connect to graph.facebook.com port 443: Connection timed outArray
(
   [url] => https://graph.facebook.com/
   [content_type] => 
   [http_code] => 0
   [header_size] => 0
   [request_size] => 0
   [filetime] => -1
   [ssl_verify_result] => 0
   [redirect_count] => 0
   [total_time] => 5.003548
   [namelookup_time] => 0.004187
   [connect_time] => 0
   [pretransfer_time] => 0
   [size_upload] => 0
   [size_download] => 0
   [speed_download] => 0
   [speed_upload] => 0
   [download_content_length] => -1
   [upload_content_length] => -1
   [starttransfer_time] => 0
   [redirect_time] => 0
   [redirect_url] => 
   [primary_ip] => 
   [certinfo] => Array
       (
       )

   [primary_port] => 0
   [local_ip] => 
   [local_port] => 0
)
There is a problem with cURL. You need to contact your server admin or hosting provider.Testing ... https://www.linkedin.com/nhome/ - https://www.linkedin.com/nhome/
....HTTPS to LinkedIn - Problem
Failed to connect to www.linkedin.com port 443: Connection timed outArray
(
   [url] => https://www.linkedin.com/nhome/
   [content_type] => 
   [http_code] => 0
   [header_size] => 0
   [request_size] => 0
   [filetime] => -1
   [ssl_verify_result] => 0
   [redirect_count] => 0
   [total_time] => 5.003194
   [namelookup_time] => 0.004179
   [connect_time] => 0
   [pretransfer_time] => 0
   [size_upload] => 0
   [size_download] => 0
   [speed_download] => 0
   [speed_upload] => 0
   [download_content_length] => -1
   [upload_content_length] => -1
   [starttransfer_time] => 0
   [redirect_time] => 0
   [redirect_url] => 
   [primary_ip] => 
   [certinfo] => Array
       (
       )

   [primary_port] => 0
   [local_ip] => 
   [local_port] => 0
)
There is a problem with cURL. You need to contact your server admin or hosting provider.

Curl 仍然安裝在我的伺服器上,我已經通過phpinfo();

重新安裝 curl 模組沒有幫助。

sudo apt-get install php5-curl
sudo service apache2 restart
Failed to connect to X port 443: Connection timed out

這看起來更像是一個網路問題,而不是php和/或curl,應該嘗試通過 shellcurl和/或複制它wget

引用自:https://serverfault.com/questions/771999