Note that there are some explanatory texts on larger screens.

plurals
  1. POHuge and long sql query delay the php session_start() until query ends
    primarykey
    data
    text
    <p>I got a cron that calls a php file and launches a huge SQL update on the database.</p> <p>something like that :</p> <pre><code>UPDATE t1 SET t1.a = (SELECT sum() FROM .... ) </code></pre> <p>This query takes seconds to execute (maybe 20sec).</p> <p>While the query is running, all the others scripts (from http or from cli) are delayed. Actually these scripts hold on the session_start() function.</p> <p>When the sql query ends, the other script (which were waiting on session_start() ) can run again (if they didn't reach the timeout) . </p> <p>The session uses file system as save handler.</p> <p>EDIT :</p> <p>Better explained in main steps :</p> <p><strong>I got 2 files</strong> </p> <p>File 1 : cron.php : is launched by a cron </p> <ol> <li>sql connection</li> <li>huge sql queries</li> </ol> <p>cron.php :</p> <pre><code>&lt;?php mysql_connect('host', 'user', 'pass'); mysql_select_db('mydb'); mysql_query('UPDATE t1 SET t1.a=(SELECT SUM(t2.a) FROM t2 WHERE "some where clauses")'); mysql_query('UPDATE t1 SET t1.b=(SELECT SUM(t2.b) FROM t2 WHERE "some where clauses")'); mysql_query('UPDATE t3 SET t3.c=(SELECT SUM(t2.b) FROM t2 WHERE "some where clauses")'); </code></pre> <p>File 2 : index.php : http reachable</p> <ol> <li>session_start()</li> <li>some codes</li> </ol> <p>index.php:</p> <pre><code>&lt;?php // index.php echo "SESSION STARTING"; session_start(); echo "SESSION STARTED"; </code></pre> <p><strong>What happens :</strong></p> <ol> <li><p>a cron launches <code>php cron.php</code> </p></li> <li><p>someone browses the website he goes to index.php</p></li> <li><p>apache launches <code>index.php</code> </p></li> <li><p>index.php holds on <code>session_start()</code></p></li> <li><p>the cron job ends</p></li> <li><p><code>index.php</code> can run normally</p></li> </ol> <p>In alternative to the 6. if the script is too much long, then i can see the following lines in the logs :</p> <pre><code>Premature end of script headers mod_fcgid: read data timeout in 40 seconds </code></pre> <p>That means that the script spent 40 second trying to read the session file</p> <p>The question is what could be the link between mysql query and the session start and what could delay the session_start() ? </p> <p>The server runs on Debian 7.</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.
 

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