PHP Processor Usage

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
fangorn
Forum Commoner
Posts: 41
Joined: Fri May 21, 2004 9:04 am

PHP Processor Usage

Post by fangorn »

For my customer, I have some intensive reports that culls through data based on a date range. I noticed that if I pick a large date range (say 1 month) PHP.exe spikes the processor to 100% for several seconds. I realize that the time that the processor is spiked is due to the report requirement and the multi-day range. But that fact that the processor spikes to 100% concerns me. In multi-threaded C++, you add a sleep to allow the thread to give back a time slice to the processor. Is there a way with PHP to do a sleep to effectively give back time to the processor? Is there anyway to force PHP to only use some max percentage of the processor? Any suggestions or ideas?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I'd suggest optimizing your code first. The [php_man]sleep[/php_man] function in php may give it's time back to the machine, but since its time units are in seconds, that's a lot of time tossed back. There is [php_man]usleep()[/php_man] as well, but does not work on windows machines until php5... if that matters.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

if you are using linux...

Code: Select all

user@host: man ulimit
fangorn
Forum Commoner
Posts: 41
Joined: Fri May 21, 2004 9:04 am

Post by fangorn »

Thanks guys. Unfortunately I'm using Windows (customer requirement). Also, this is a legacy system where the database design is so poor that optimizing my code has only gone so far. I know that a redesign would significantly help the total report time. I'll look at usleep(), thanks alot for the help.
Post Reply