note 115749 added to function.curl-multi-exec

From: Date: Wed, 17 Sep 2014 14:30:51 +0000
Subject: note 115749 added to function.curl-multi-exec
Groups: php.notes 
Request: Send a blank email to php-notes+get-200464@lists.php.net to get a copy of this message
when you run curl_multi_exec() on the OS X mavericks system you may not get the right return, the scripts may running and running but no return value. That's because on the OSX system with the php version 5.3.8+, when you call the curl_multi_exec() method before calling the curl_multi_select(), may always return the -1. So here change a little code to running the curl_multi_exec() successful on OSX below. <?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/115749 Del: integrated -- https://master.php.net/note/delete/115749/integrated Del: useless -- https://master.php.net/note/delete/115749/useless Del: bad code -- https://master.php.net/note/delete/115749/bad+code Del: spam -- https://master.php.net/note/delete/115749/spam Del: non-english -- https://master.php.net/note/delete/115749/non-english Del: in docs -- https://master.php.net/note/delete/115749/in+docs Del: other reasons-- https://master.php.net/note/delete/115749 Reject -- https://master.php.net/note/reject/115749 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#200464) next »