Question

I am looking to implement a rudimentary dynamic throttling mechanism on my PHP/Apache web server based on server load and am wondering how I might get some idea of how busy the server is, either from the server itself (ideally) or from the client.

The client polls the server every x seconds to get an updated value. I basically want to throttle x based on load, so that 1000 connections aren't all trying to hit it every 5 seconds.

One thought is to simply check the average response time of the server and compare it against some baseline, but I think it would be preferable if the server could actually figure out how busy it was itself and return this value as metadata in a response.

Was it helpful?

Solution

You could use the load averages, retrievable using sys_getloadavg(). Use the value(s) returned in the last poll to decide how long to wait before the next.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top