【发布时间】:2015-01-02 11:49:20
【问题描述】:
我有两台服务器在不同的软件版本中运行类似的网络应用程序。
两台服务器都运行 CentOS 6.5
一个有 Apache 2.2 php 5.3
另一个正在运行 Apache 2.4 php 5.5
此应用的主要功能之一是定期从远程 URL 下载 CSV 文件
这是使用 cURL 和以下代码完成的:
$filename = 'export.csv';
$url = 'http://www.someaddress.com/export/' . $filename;
$curl = curl_init();
$fd = fopen(DIR_FS_ADMIN . 'temp/' . $filename , "w");
curl_setopt ($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_FILE, $fd);
curl_exec ($curl);
curl_close ($curl);
如您所见,一段非常简单的代码在 PHP 5.3 中运行良好
这是 curl_getinfo() 的结果
[content_type] => text/csv
[http_code] => 200
[header_size] => 209
[request_size] => 95
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 1.98925
[namelookup_time] => 0.816404
[connect_time] => 0.817009
[pretransfer_time] => 0.831392
[size_upload] => 0
[size_download] => 13564110
[speed_download] => 6818705
[speed_upload] => 0
[download_content_length] => 13564110
[upload_content_length] => -1
[starttransfer_time] => 0.834829
[redirect_time] => 0
[certinfo] => Array
(
)
[redirect_url] =>
)
Error Code: 0
这些是相同代码在 5.5 上运行的结果
[content_type] =>
[http_code] => 0
[header_size] => 0
[request_size] => 0
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 126.332476
[namelookup_time] => 0.000369
[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
)
7 Failed to connect to www.someaddress.com/export/: Connection timed out
当然,在发布之前我已经研究并尝试了很多选项,增加超时时间,尝试资源的 SSL 版本,并使用不同的 curl_setopt 玩了很多,我总是无法从 5.5 连接应用程序。
我知道在 5.5 上对 cURL 扩展进行了一些更改,但我可以通过 Google 搜索找到上传问题,我还尝试了完全不同的选项,例如使用 file_get_contents,但仍然没有,只是超时。
两台服务器都位于同一个地方,并且 URL 是完全打开的,所以我真的怀疑问题出在文件位置,因为当我在 5.3 服务器上运行代码时仍然可以正常工作。
【问题讨论】:
标签: php apache curl download php-5.5