【发布时间】:2013-11-28 17:56:03
【问题描述】:
我正在尝试在我的 Mac OS X (Mavericks) 下从 php.net 运行这段简单的代码来尝试 cURL 多执行功能:
<?php
// create both cURL resources
$ch1 = curl_init();
$ch2 = curl_init();
// set URL and other appropriate options
curl_setopt($ch1, CURLOPT_URL, "http://lxr.php.net/");
curl_setopt($ch1, CURLOPT_HEADER, 0);
curl_setopt($ch2, CURLOPT_URL, "http://www.php.net/");
curl_setopt($ch2, CURLOPT_HEADER, 0);
//create the multiple cURL handle
$mh = curl_multi_init();
//add the two handles
curl_multi_add_handle($mh,$ch1);
curl_multi_add_handle($mh,$ch2);
$active = null;
//execute the handles
do {
$mrc = curl_multi_exec($mh, $active);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);
while ($active && $mrc == CURLM_OK) {
if (curl_multi_select($mh) != -1) {
do {
$mrc = curl_multi_exec($mh, $active);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);
}
}
//close the handles
curl_multi_remove_handle($mh, $ch1);
curl_multi_remove_handle($mh, $ch2);
curl_multi_close($mh);
?>
这不起作用,因为我得到的唯一输出是:
PHP 致命错误:超过 30 秒的最大执行时间
这是我的环境:Mac OS X 10.9、PHP 5.4.17、Apache 2.2.24。
cUrl 已安装,因为我的常规 curl“单个”请求运行良好。
我认为这是 Mac OS 的问题,但我找不到任何解决方法。你有什么想法吗?
编辑:我在 Linux 服务器上尝试了相同的代码,一切正常。
【问题讨论】:
-
尝试使用set_time_limit(0)改变时间限制;//不适合生产现场,仅供测试使用。
-
它只是运行,运行,运行,但没有任何反应......
标签: php macos curl curl-multi