php-curl没有连接到远程主机,标题似乎是空的

时间:2015-07-21 22:06:44

标签: php php-curl

我将我的一台服务器配置为通过邮件接受文件,转换它们并将它们作为响应发送。 php服务器通过curl使用此功能。

我的php脚本中的重要部分看起来像这样

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_PORT, $port);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, array('file_contents' => '@' . $filename));
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);

file_put_contents($filename . '.png', curl_exec($ch));

print_r(curl_getinfo($ch));
echo curl_errno($ch);

curl_close($ch);

然而,似乎curl甚至没有连接到其他服务器而curl_getinfo只返回

Array
(
    [url] => (redacted)
    [content_type] => 
    [http_code] => 0
    [header_size] => 0
    [request_size] => 0
    [filetime] => -1
    [ssl_verify_result] => 0
    [redirect_count] => 0
    [total_time] => 0
    [namelookup_time] => 0.036982
    [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] => (redacted)
    [certinfo] => Array
        (
        )
)

即使我增加超时,curl_errno也会返回28(CURLE_OPERATION_TIMEDOUT)。正如我之前所说,它似乎甚至没有与远程主机建立连接。可以使用Web浏览器连接到给定的URL。

0 个答案:

没有答案