Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Calling session_start(); can harm the performance of your application.</p> <p>The following code will trigger an E_NOTICE, but won't harm that much performance wise</p> <pre><code>&lt;?php session_start(); session_start(); ?&gt; </code></pre> <p>But calling the following will harm the performance! But it's still useful. If you have a script that takes like 3 minutes to run and is called with XHR (js). In this case it's useful to use the session_write_close. otherwise the request to the server is blocked until the sessions are released. It could happen that you want to use the sessions at the start of the script and at the end of the script.</p> <pre><code>&lt;?php session_start(); session_write_close(); session_start(); ?&gt; </code></pre> <p>But, when you call the session_start(); all information is deserialized, and when you call session_write_closed() it's serialized. So if you have a lot of data it can be really slow!</p> <p>The following test shows how much impact it has.</p> <p>1.0130980014801 sesion_start + close with empty session</p> <p>1.0028710365295 normal loop without session</p> <p>12.808688879013 a lot data in the session with start + close</p> <p>1.0081849098206 normal loop again (useless kinda)</p> <pre><code>&lt;?php //start and clear first session session_start(); session_destroy(); session_write_close(); //test one if(true) { //test loop one $start = microtime(true); for($i = 0; $i &lt; 1000; $i++) { session_start(); usleep(100); session_write_close(); } $end = microtime(true); echo($end - $start); //test loop 2 echo('&lt;br /&gt;'); $start = microtime(true); for($i = 0; $i &lt; 1000; $i++) { usleep(100); } $end = microtime(true); echo($end - $start); } //fill the array with information so serialization is needed session_start(); $_SESSION['test'] = array(); for($i = 0; $i &lt; 10000; $i++) { $_SESSION['test'][$i] = chr($i); } session_write_close(); echo('&lt;br /&gt;'); //test two if(true) { //test loop one $start = microtime(true); for($i = 0; $i &lt; 1000; $i++) { session_start(); usleep(100); session_write_close(); } $end = microtime(true); echo($end - $start); //test loop 2 echo('&lt;br /&gt;'); $start = microtime(true); for($i = 0; $i &lt; 1000; $i++) { usleep(100); } $end = microtime(true); echo($end - $start); } ?&gt; </code></pre>
    singulars
    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. 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.
    3. VO
      singulars
      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