tags:

views:

209

answers:

2

How in php can I get at the number of apache children that are currently available (status = SERVER_READY in the apache scoreboard)?

I'm really hoping there is a simple way to do this in php that I am missing.

A: 

You could execute a shell command of ps aux | grep httpd or ps aux | grep apache and count the number of lines in the output.

exec('ps aux | grep apache', $output);
$processes = count($output);

I'm not sure which status in the status column indicates that it's ready to accept a connection, but you can filter against that to get a count of ready processes.

ceejayoz
+1  A: 

If you have access to the Apache server status page, try using the ?auto flag:

http://yourserver/server-status?auto

The output is a machine-readable version of the status page. I believe you are looking for "IdleWorkers". Here's some simple PHP5 code to get you started. In real life you'd probably want to use cURL or a socket connection to initiate a timeout in case the server is offline.

<?php

$status = file('http://yourserver/server-status?auto');
foreach ($status as $line) {
  if (substr($line, 0, 10) == 'IdleWorkers') {
    $idle_workers = trim(substr($line, 12));
    print $idle_workers;
    break;
  }
}

?>
giltotherescue