Following a PHP web site from an Apache server is loaded through the browser, client side javascript is delivering AJAX demands every 5 seconds to some PHP update script. The AJAX response, encoded in JSON, can be very large, so I wish to send this is the empty array '[]' if there's no change because the previous AJAX request, or even the entire array that contains various JSON objects if there's been a big change because the last AJAX demands.

To implement delivering '[]' or even the full array I am utilizing a session variable. My update script appears like:

$output = '[]'; // server is running PHP 5.1 so can't use built in JSON encode
// code here queries a database and updates $output based on the query result
if (isset($_SESSION['previous_output'])) {
    if ($_SESSION['previous_output'] == $output) {
        echo '[]';
    } else {
        $_SESSION['previous_output'] = $output;
        echo $output;

After applying the above mentioned script, the net server administrator observed "a lot ofInch httpd processes being produced and hanging out, eventually getting the server to some grinding halt.

After I take away the code including the session variables, some httpd processes still hold off, however the "backlog" isn't as bad, and finally the processes disappear before there's noticeable effect on the server.

The net server isn't heavily used, serving maybe six "visitors' anytime. The site doing the five second AJAX demands is "protected", meaning merely a single admin user can can get on at any given time.

I discovered another posting at PHP MySQLi Singleton for Ajax-Demands finish directly into many processes that sounds similar, also it refers back to the AJAX Push Engine (APE) project, which I must investigate further eventually. However, I'm presently tight on some time and assets (e.g. cannot setup an APE server...), and so i am in a lost regarding what you can do.

Any advice regarding how to perform the 5 second AJAX demands without negatively affecting server performance? Why would using the session variable make this type of noticeable difference?

Apache attempts to maintain some idle employees to process incoming demands. These configurations could be tweaked (min quantity of idle employees, max quantity of employees - of particular interest MaxRequestsPerChild, try lowering this value). This should not result in a problem - presuming your script is terminating properly (this should not be an problem for that typical web application). You can find an intensive answer in the serverfault community.

Also, with respect to the server load (# of active customers, assets the api uses, etc.), you will need to scale you application (research autoscaling with amazon's ec2 service).