I’m doing some heavy image manipulation in php and I would like to show the user how things are progressing. So I tried doing something like this:
for($i = 0; $i < $rowCount; $i++) {
session_start();
$_SESSION['progress'] = $i/ $rowCount;
session_write_close();
processLine($i);
}
And then I’m using AJAX calls to another php file which basically returns the value of $_SESSION[‘progress’]. Problem is, it is not set. Is this because you shouldn’t start a session more than once per file? If I just open the session and don’t close it between each row, the SESSION variable is locked and my polling file won’t be handled until the whole image manipulation is done.
Any way to get this to work using sessions? I think it might work if I put the progress in a database or file, but that’s slow and we’ll have to do a bit of work to identify users (using ips or session ids). Using sessions would take care of these things.
This is because php locks the session file. The first process that still uses the same session locks the file, the ajax call uses the same session ID, thus trying to access the same session file but it can’t since it is locked by php until the first process finishes up.
This is the answer to your question. If you want to know how to fix it, I am not sure, I have to think about it.