Reputation: 826
I know that I have seen a method out there in PHP that when called will give me the current CPU status, but I cannot remember it, and google searches are not coming up with anything for me.
Basically, I have a chat program, and I need to make sure that it doesn't wreak havoc on the server. So I would like to, when a message is posted (as that is the only time that PHP is used, otherwise just straight .txt file), check to see what the status of the server is. That way I can regulate how often ajax requests are sent out by the client, depending on the health of the server.
Upvotes: 0
Views: 213
Reputation: 400932
If you are on a Linux-based server, you can use sys_getloadavg
, which will get you the system load average :
Returns three samples representing the average system load (the number of processes in the system run queue) over the last 1, 5 and 15 minutes, respectively.
This should be better than using a "snapshot" of the CPU-load at a given instant : the 1 minute and 5 minutes values are quite interesting, as they give you an average value for a short period of time.
It also gives takes into account more that only the CPU load -- for more informations, you can take a look at the Load average page on wikipedia.
But note that this function is not implemented on windows platform.
Which mean you'll have to make that call conditionnal, depending on the underlying operatinf system.
Upvotes: 5