I have some PHP scripts that do various calls to a database etc. Some of these calls are expensive (~50ms - 100ms), but produce useful (but not essential) results.
Everything is fine provided I get less than 5 page views per second (which is most of the time).
But sometimes I get up to 20 page views per second. This causes my server to start swapping as processes pile up. Once swapping starts, it doesn't stop until the server gets a few seconds of peace and quiet, which may take a long time.
What I would like to do is to inexpensively detect the server load, and start serving reduced functionality pages if the load is high. The reduced functionality pages would execute much faster, keeping the number of active processes to a manageable number.
So is there a way to measure server load from within PHP that is inexpensive? I don't want to execute another process to find out.
Ta,
Steve