Surinder
Surinder

Reputation: 425

How to I close an apache2 process when my execution is complete in php

I have a simple code which is as follows:

<?php
require( 'config.php' );
if (isloggedin()) {
    echo 1;
} else {
    echo 0;
}

I call above file via ajax after every 10 seconds

<script >
setInterval(function() {
    // Creating the XMLHttpRequest object
    var request = new XMLHttpRequest();

    // Instantiating the request object
    request.open("GET", "/checkSession.php");

    // Defining event listener for readystatechange event
    request.onreadystatechange = function() {
        // Check if the request is compete and was successful
        if(this.readyState === 4 && this.status === 200) {
            if(!this.responseText){                
                location.reload();
            }
        }
    };

    // Sending the request to the server
    request.send();
    
}, 10 * 1000); 
</script>';

Above code is in production and when I check my apache server status on this url "https://mywebsite.com/server-status" it was filled with queries from 0-14 18963 1/105/266333 K 0.58 3 13 2.0 3.55 3430.66 69.159.70.180 http/1.1 mywebsite.com:443 GET /checkSession.php HTTP/1.1

There are more than 90 requests as above (for checkSession) when there are 140 users online. So I checked that apache2 is using mpm_prefork module to handle requests. So each request is handled by a process or child process.

Now as per server-status I suppose processes are getting created everytime checkSession.php file is being called from user browser ajax, but not getting destroyed after execution.

Could anyone please put some light on this and educate us all.

Upvotes: 0

Views: 37

Answers (0)

Related Questions