Search code examples
phpapacheapicronblocking

Apache same orgin request blocking


When I try to load two of the same page from my server in different tabs of the same browser, it waits for one to finish before starting the other. This is fine but I have a cron process which needs to call several calls to the same script and I can't have this type of blocking behavior. I think it is because the process has the same session/connection with the server and the default behavior is to only allow one request at a time from the same source... how can I get around this? What I want to be able to do is have a cron process be able to fire off calls to one of my scripts and apache spin up a new instance of the targeted script to handle the request for each one. Is this possible?


Solution

  • Are you using PHP's standard file-based sessions? PHP locks the session when you do a session_start() and keeps the file locked until the script exits, or you do a session_write_close().

    This has the effect of preventing any OTHER session-enabled pages from being served up, as they can't get at the session file until the lock is removed.

    session_write_close() can be called at any point in the script. All it does is write out the _SESSION array as it is at that moment, but leaves the array available for reading. You can always re-open the session later on the script if you need to make any modifications.

    Basically, you'd have

    <?php
    
    session_start(); // populate $_SESSION;
    session_write_close(); // relinquish session lock
    
    .... dome some really heavy duty long computations
    
    session_start();
    $_SESSION['somekey'] = $new_val;