Bug #64191 [Opn->Nab]: "curl_multi_close" example code needlessly use 100% cpu..

From: Date: Wed, 09 Oct 2013 06:59:45 +0000
Subject: Bug #64191 [Opn->Nab]: "curl_multi_close" example code needlessly use 100% cpu..
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-10457@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=64191&edit=1 ID: 64191 Updated by: krakjoe@php.net Reported by: divinity76 at gmail dot com Summary: "curl_multi_close" example code needlessly use 100% cpu.. -Status: Open +Status: Not a bug Type: Bug Package: Documentation problem Operating System: Irrelevant PHP Version: Irrelevant Block user comment: N Private report: N New Comment: Examples in the documentation are not intended to show best practices, but illustrate functionality: they are *meant* to be simple. I therefore do not see a reason to change the example, lets keep it simple :) Previous Comments: ------------------------------------------------------------------------ [2013-02-11 19:48:59] divinity76 at gmail dot com Description: ------------ as of writing, the example code for curl_multi_close is <?php // create both cURL resources $ch1 = curl_init(); $ch2 = curl_init(); // set URL and other appropriate options curl_setopt($ch1, CURLOPT_URL, "http://www.example.com/"); 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); $running=null; //execute the handles do { curl_multi_exec($mh,$running); } while ($running > 0); //close the handles curl_multi_remove_handle($mh, $ch1); curl_multi_remove_handle($mh, $ch2); curl_multi_close($mh); ?> i believe this code will be stuck using all cpu it can on do{curl_multi_exec($mh,$running);}while($running>0); part, until both curl handles are done.. and i believe a solution is curl_multi_select ; there already is example codes on curl_multi_exec / curl_multi_init that use curl_multi_select to do non-busy-waiting (or whatever it's called, idk), maybe copy&paste the example code from 1 of those? Expected result: ---------------- small cpu usage Actual result: -------------- high cpu usage ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=64191&edit=1

« previous php.doc.bugs (#10457) next »