views:

58

answers:

1

Hi, I'm creating a project in which a server receives operations from clients to apply to a local server document. The server and client both share the same document and therefore each message the client sends contains an MD5 hash, which the server compares to after generating its own hash to ensure the server and client documents are synchronized.

My question is, if the server is overloaded, could I somehow detect this in PHP, which would in turn let me decide whether I want to execute the hash generation function or not?

Perhaps in the scenario defined, this is not a perfect use-case, but I'm interested in this approach in general.

+2  A: 

Assuming you are under Linux, you can get processor load averages by reading from a file /proc/loadavg which contains 3 numbers separated by spaces. You can also call uptime command from php exec('uptime') and parse its output, which also contains load averages (among other stuff).

How to interpret load averages - I usually take 1.0 * cores as a maximum healthy load. So if you have 4 cores then anything above 4.0 would indicate that processor is doing some heavy calculations and better wait.

serg
I was aware of this, but was hoping there would be some easier cross-platform way. But thanks.
teehoo