note 88942 added to function.curl-multi-exec

From: Date: Sat, 14 Feb 2009 13:10:12 +0000
Subject: note 88942 added to function.curl-multi-exec
Groups: php.notes 
Request: Send a blank email to php-notes+get-150672@lists.php.net to get a copy of this message
With the current examples using curl-multi-exec is still not much better then just using file_get_contents. Your script has to needlessly wait at least the maximum of all connection times (instead of the sum). A better solution would be to run the connections as another thread in parallel to other parts of the script: <?php $cm = new CurlManager(); $handle1 = $cm->register($url1); $handle2 = $cm->register($url2); $cm->start(); # start connections $result1 = $cm->result($handle1); # surely NULL because connection has not been finished sleep($seconds); # do something else (including use of other CurlManagers!) $result1 = $cm->result($handle1); # maybe NULL if connection takes longer then $seconds $cm->finish(); # wait if some connections are still open $result1 = $cm->result($handle1); $result2 = $cm->result($handle2); ?> But I am not sure whether such a CurlManger is possible, especially if you may want to use multiple of them (for instance because some URLs are not known at the start of the script). It's a pain that PHP does not support real threads. ---- Server IP: 217.160.72.57 Probable Submitter: 80.128.42.77 ---- Manual Page -- http://www.php.net/manual/en/function.curl-multi-exec.php Edit -- https://master.php.net/note/edit/88942 Del: integrated -- https://master.php.net/note/delete/88942/integrated Del: useless -- https://master.php.net/note/delete/88942/useless Del: bad code -- https://master.php.net/note/delete/88942/bad+code Del: spam -- https://master.php.net/note/delete/88942/spam Del: non-english -- https://master.php.net/note/delete/88942/non-english Del: in docs -- https://master.php.net/note/delete/88942/in+docs Del: other reasons-- https://master.php.net/note/delete/88942 Reject -- https://master.php.net/note/reject/88942 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#150672) next »