安装了php5-curl,但curl_exec()
返回null
,curl_errno()
返回0
,curl_error()
返回null
,curl_getinfo()
看起来像curl_exec()
从未被解雇过。
代码示例
$this->curl = curl_init();
$agent = 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Firefox/52.0';
$curlOptions = array(
CURLOPT_URL=>str_replace(' ', '%20', $url),
CURLOPT_RETURNTRANSFER=>true,
CURLOPT_USERAGENT=>$agent,
CURLOPT_BINARYTRANSFER=>true,
CURLOPT_CUSTOMREQUEST=>"GET",
CURLOPT_AUTOREFERER=>true,
CURLOPT_CONNECTTIMEOUT=>5,
CURLOPT_TIMEOUT=>600,
CURLOPT_FOLLOWLOCATION=>true,
CURLOPT_MAXREDIRS=>20,
CURLOPT_SSL_VERIFYPEER=>false
);
curl_setopt_array($this->curl, $curlOptions);
$result = curl_exec($this->curl);
$status = curl_getinfo($this->curl);
$this->log->ToLog('HTTP error on downloading ' .$url.' ; error = ' . curl_errno($this->curl) . " => ". curl_error($this->curl) . ' ; status = '. json_encode($status) , 'info');
在日志中我可以看到
下载
https://cdn-a.verkkokauppa.com/576/images/83/2_175586-1250x758.jpeg
时出现HTTP错误; error = 0 => ; status = {“url”:“https://cdn-a.verkkokauppa.com/576/images/83/2_175586-1250x758.jpeg”,“content_type”:null,“http_code”:0,“header_size”:0 “request_size”:0 “FILETIME”:0 “ssl_verify_result”:0 “redirect_count”:0 “TOTAL_TIME”:0 “namelookup_time”:0 “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”:[], “primary_port”:0 “local_ip”: “”, “LOCAL_PORT”:0}
但file_get_contents()
在这种情况下可以正常工作。发生了什么?我该如何解决?