Monitoring Number of Apache Requests with PHP

By | June 5, 2008

Today I’ll come with a small piece of code that will allow you to monitor the number af requests to Apache that are processed at the moment. This might help you to prevent server overload as you will always know what’s happening to your Apache. We’ll parse server-status page and will take the number of requests. Simple and fast< as usual.

<?

// Getting the page with server status

$sekas=file_get_contents(“http://localhost/server-status”);
// Locating the position of the number of requests displayed

$pos=strpos($sekas, “requests currently being processed”)-5;
// Creating regexp pattern for replacement
$pattern=”[^0-9]”;
// Replacing non-numeric symbols
$traseu=ereg_replace($pattern, “”, substr($sekas, $pos, 5));
echo $traseu;
?>

Hope this code will help you.