How to reduce CPU usage in a cycle? [ag]

From: Date: Thu, 11 Dec 2003 15:03:44 +0000
Subject: How to reduce CPU usage in a cycle? [ag]
Groups: php.general 
Request: Send a blank email to php-general+get-172477@lists.php.net to get a copy of this message
Hello! I'm having a problem with my php script on my linux web server. In that script there is a cycle with some math calculations (about ~30 steps), the execution time is less 1 second, but the script loads the server CPU up to 90%... I've optimized script already to the minimum math function, anyway, it still overloads the CPU. How can I reduce the CPU load? It seems that usleep() does not help much, especially in Windows (it's not supported). How can I give system a portion of time in the end of each step (I don't mind if it will increase the job time)? Is there a solution for both Windows and Linux? For instance, in C++ under Windows I would do this: do { [... math calculations ...] while(::PeekMessage(&message,NULL,0,0,PM_NOREMOVE)) if (!theApp.PumpMessage()) break; } while(!quit); This gives system to redraw screen, process any other events during long cycles... Is there similar approach in PHP for web server programming? p.s. Would be nice to know other techniques to reduce CPU load ;) Thank you!

« previous php.general (#172477) next »