Alw1n
asked on
PHP loop and high cpu usage
Hi,
I have a loop in a php script (5.2.11 on IIS) that builds data from a database, there could be many lines (20k+) and it can run for several seconds. I have noticed that the cpu usage goes up to 100% while this is busy which is understandable, I was wondering:
1 - Is this cpu usage is going to affect the server badly (for other requests) or will it give resources to other requests as needed?
2 - What I could do about this to free up some cpu time (ala vb6 DoEvents type thing)
I have a loop in a php script (5.2.11 on IIS) that builds data from a database, there could be many lines (20k+) and it can run for several seconds. I have noticed that the cpu usage goes up to 100% while this is busy which is understandable, I was wondering:
1 - Is this cpu usage is going to affect the server badly (for other requests) or will it give resources to other requests as needed?
2 - What I could do about this to free up some cpu time (ala vb6 DoEvents type thing)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Heavy CPU usage during database retrival normally means that you have not defined sufficient indexes for your retrieval. Ensure that EVERY column mentioned in a WHERE, ORDER BY or JOIN clause has an index in the database.
ASKER
Thanks, I haven't really noticed that a lack of indexes causes high cpu usage, just that the queries take longer but I had created the indexes already anyway for performance reasons
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks All, I split the points to be fair
ASKER
Memory is fine as I have set this correctly, it's just the cpu that is taking a beating.