Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h2>Experiment:</h2> <p><strong>Significant changes from original code:</strong></p> <p>1) Using implicit_flush and all buffers are flushed before doing anything.<br> 2) Instead of outputting just a space, the code outputs the iteration number and 1023 bytes of other data to tell the browser that we have good amount of output to display. A normal known trick.<br> 3) Along with saving the time in the output text file, it also saves the total iterations that the code ran.</p> <p><strong>The code used:</strong></p> <pre><code>&lt;?php // Tricks to allow instant output @ini_set('implicit_flush', 1); for ($i = 0; $i &lt; ob_get_level(); $i++) ob_end_flush(); ob_implicit_flush(1); //Your Code starts here ignore_user_abort(true); set_time_limit(0); $begin_time = microtime(true); $elapsed_time = 0; while(!connection_aborted()) { //this I changed, so that a looooong string is outputted echo $i++.str_repeat(' ',1020).'&lt;br/&gt;'; flush(); usleep(1000000); } $elapsed_time = microtime(true) - $begin_time; $timer_seconds = $elapsed_time; //10 seconds //Writes to file the number of ITERATIONS too along with time $fp = fopen('4765107.txt', 'w'); fwrite($fp, 'Time Elapsed: '.$timer_seconds); fwrite($fp, "\nIterations: ".$i); fclose($fp); ?&gt; </code></pre> <p><strong>Live Demo:</strong></p> <ul> <li><p>Now, here is the code to run: <a href="http://work.sktnetwork.com/so/4765107.php" rel="nofollow">http://work.sktnetwork.com/so/4765107.php</a></p></li> <li><p>And here is the .TXT file it generates: <a href="http://work.sktnetwork.com/so/4765107.txt" rel="nofollow">http://work.sktnetwork.com/so/4765107.txt</a></p></li> </ul> <hr> <h2>What I got:</h2> <p>1) When code is run for 10 iterations and STOP button on browser is clicked, the output file shows 13 iterations with ~ 13.01 seconds taken.</p> <p>2) When code is run for 20 iterations and STOP button on browser is clicked, the output file shows 23 iterations with ~ 23.01 seconds taken.</p> <hr> <h2>Inferences &amp; Conclusion:</h2> <p>1) The script actually does NOT stops when the STOP button is clicked but after 2-4 seconds of clicking it. So, there are more iterations that what appears in the browser.</p> <p>2) The number of iterations is SAME as the number of seconds it takes to execute, as shown in output file.</p> <p>Therefore, there is no error and apparently no bugs, it's just the latency time between clicking the STOP button and the script actually stopping.</p> <hr> <p><strong>Notes:</strong></p> <p>1) Server: A Linux VPS.<br> 2) Clients tested: Firefox and Chrome.<br> 3) <strong>As the script ends 2-4 seconds after STOP is clicked, it takes around 3-4 seconds for the output file to be updated for the current test.</strong></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.
    3. 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