Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The session information is a resource that can only be used exclusively, and you have not taken this into account.</p> <p>Specifically, under default settings <code>session_start</code> causes PHP to acquire an exclusive lock on a file that contains the session data. This file is not unlocked until the script exits or <code>session_write_close</code> is called.</p> <p>In your example, <code>process.php</code> acquires the lock and starts working. In the meantime, <code>progress.php</code> tries to <code>session_start()</code> and cannot (due to the lock). Enough time needs to pass for <code>process.php</code> to complete and exit (thus releasing the lock) before the request for progress information can be satisfied.</p> <p>A small change you can make that will have immediate effect is to call <code>session_write_close</code> and <code>session_start</code> from within your worker loop:</p> <pre><code>for ($i=0; $i &lt;= $totalItems; $i++) { session_start(); $_SESSION['currentItem'] = $i; $_SESSION['percentComplete'] = round(($i / $totalItems * 100)); session_write_close(); } </code></pre> <p>This will allow the two scripts to take turns locking the session storage file, so you will see things working as intended. However, performance will <strong>tank</strong> (this is a really impolite way to treat the session storage file).</p> <p>If you had need to do something like this in the real world, it would be necessary to utilize something other than the session data to enable this exchange of information between the PHP scripts (e.g. an in-memory cache like APC or memcached).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload