1

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?

hackartist
  • 5,172
  • 4
  • 33
  • 48

2 Answers2

3

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;
Marc B
  • 356,200
  • 43
  • 426
  • 500
  • I'm not sure if this is the whole problem but I think it is definitely part of the issue... I am testing with it right now and I'll let you know how it goes. – hackartist Nov 01 '11 at 22:44
  • I think that this was some of the blocking so thanks for the info. – hackartist Nov 01 '11 at 22:51
0

I don't think that there is any problem with php continue, in fact I like how it behaves

Use continue 2; because continue will do the same as brake in the switch and the for, while, foreach, etc. loops will continue their course after coming out of the switch.

The following example will echo only 1, because I am breaking from the switch and the continuing of the foreach.


$un_array=array(1,2);

foreach($un_array as $num)
{
    switch($num)
    {
        case 1:
        //nothing
        break;
        case 2:
            continue 2;
        break;
    }

    echo $num;

}

exit;