Re: limit in a loop function to prevent server load
| From: | timo stamm | Date: | Wed, 04 Sep 2002 21:41:31 +0000 |
| Subject: | Re: limit in a loop function to prevent server load | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-115235@lists.php.net to get a copy of this message | ||
Hi Electroteque,
Am Dienstag den, 3. September 2002, um 10:14, schrieb Bas Jobsen:
I think for($i=0; $i<100;$i++){ // do something sleep(1); }; makes more sense. If that is already to much sleep: $sleepinterval = 10; $s = $sleepinterval; for ($i=0; $i<100;$i++) { // do something if (!$s--) {sleep(1);$s = $sleepinterval;}; }; On every 10th (or whatever you define as $sleepinterval) iteration, the interpreter will sleep for a second. But this still aint a sophisticated load balancing :-) Timohi there i was wondering if there was a way to limit the ammount of items in a loop to execute sleep then execute the rest of the items to prevent server load ?for($i=0;.......) { if($i>0&&$i%100==0)sleep(10); }