Hi Electroteque,

Am Dienstag den, 3. September 2002, um 10:14, schrieb Bas Jobsen:
>> hi 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);
> }


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 :-)


Timo


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to