0

我将我的一台服务器配置为通过邮寄接受文件,转换它们并将它们作为响应发送。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)。正如我之前所说,它似乎甚至没有建立与远程主机的连接。可以使用网络浏览器连接到给定的 url。

4

0 回答 0