I posted the following on stackoverflow.com and some posters suggested that this forum could help. The recap is as follows:

After a PHP web page from an Apache server is loaded by the browser, client side javascript is sending AJAX requests every 5 seconds to a PHP update script. The AJAX response, encoded in JSON, can be quite large, so I want to send simply the empty array '[]' if there is no change since the previous AJAX request, or the entire array containing various JSON objects if there has been a change since the last AJAX requests.

To implement sending '[]' or the full array I'm using a session variable. My update script looks like:

<?php
session_start();
$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 implementing the above script, the web server administrator noticed "too many" httpd processes being created and hanging around, eventually bringing the server to a grinding halt.

When I remove the code involving the session variables, some httpd processes still hang around, but the "backlog" is not as bad, and eventually the processes go away before there is noticeable impact on the server.

The web server is not heavily used, serving maybe half a dozen "visitors' at any time. The web page doing the 5 second AJAX requests is "protected", meaning only a single admin user can access it at a time.

I found another posting at http://stackoverflow.com/questions/6545573/php-mysqli-singleton-for-ajax-requests-end-in-to-many-processes that sounds similar, and it refers to the AJAX Push Engine (APE) project, which I would like to investigate further eventually. However, I am currently pressed for time and resources (e.g. cannot setup an APE server...), so I am at a lost as to what can be done.

Any advice on how to do the 5 second AJAX requests without adversely impacting server performance? Why would the use of the session variable make such a noticeable difference?

link|improve this question
It isn't really clear what is meant by 'too many' httpd processes. When we added AJAX code to update the site we started to realize that some people leave tabs open to pages for a long time. Are you sure you aren't just seeing that you have several users leaving pages open so you just end up having to support more than just the 'half a dozen' visitors, but now also everyone who leaves tabs open? We worked around this by both increasing the number of connection slots available and putting a timeout in the updater. – polynomial Aug 21 '11 at 7:57
feedback

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
or
required, but never shown

Browse other questions tagged or ask your own question.