note 115748 added to function.curl-multi-exec

From: Date: Wed, 17 Sep 2014 14:22:56 +0000
Subject: note 115748 added to function.curl-multi-exec
Groups: php.notes 
Request: Send a blank email to php-notes+get-200463@lists.php.net to get a copy of this message
当在OS X mavericks中运行curl_multi_exec()时, 可能会得不到想要的结果, 因为脚本会一直执行但是却没有返回值, 这是因为在OS X中当php在5.3.8以上版本时, 在调用curl_multi_exec()方法之前curl_multi_select()会一直返回-1, 所以这里改写一下脚本, 可以在OS X中成功执行: <?php $ch1 = curl_init(); $ch2 = curl_init(); // 设置URL和相应的选项 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); // 创建批处理cURL句柄 $mh = curl_multi_init(); // 增加2个句柄 curl_multi_add_handle($mh,$ch1); curl_multi_add_handle($mh,$ch2); $active = null; do { $mrc = curl_multi_exec($mh, $active); } while ($mrc == CURLM_CALL_MULTI_PERFORM); while ($active && $mrc == CURLM_OK) { // add this line while (curl_multi_exec($mh, $active) === CURLM_CALL_MULTI_PERFORM); if (curl_multi_select($mh) != -1) { do { $mrc = curl_multi_exec($mh, $active); if ($mrc == CURLM_OK) { while($info = curl_multi_info_read($mh)) { var_dump($info); } } } 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); ?> ---- Server IP: 72.52.91.14 Probable Submitter: 180.159.77.5 ---- Manual Page -- http://php.net/manual/en/function.curl-multi-exec.php Edit -- https://master.php.net/note/edit/115748 Del: integrated -- https://master.php.net/note/delete/115748/integrated Del: useless -- https://master.php.net/note/delete/115748/useless Del: bad code -- https://master.php.net/note/delete/115748/bad+code Del: spam -- https://master.php.net/note/delete/115748/spam Del: non-english -- https://master.php.net/note/delete/115748/non-english Del: in docs -- https://master.php.net/note/delete/115748/in+docs Del: other reasons-- https://master.php.net/note/delete/115748 Reject -- https://master.php.net/note/reject/115748 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#200463) next »