Note that there are some explanatory texts on larger screens.

plurals
  1. POQuerying database in a loop, loop with a sleep, or separate request
    primarykey
    data
    text
    <p>I'm considering the 3 options and ill take more suggestions if any come up.</p> <p><strong>The problem</strong>: I keep getting advised to ditch the sleep and I don't have the background to pick between the three</p> <p>I keep getting told that sleep is very bad to use in a php script but no one ever highlights why. I intend for the system to be scalable ie the solution to this problem could be used 10 to 100 fold.</p> <p>Option 1: sleep</p> <pre><code>$timer = time() + (30); while($done==0){ $result = mysqli_query($mysqli, $query); $row_cnt = mysqli_num_rows($result); if ($row_cnt&gt;0){ $row = mysqli_fetch_array($result); print $row[0]; $done=1;} else{ $current = time(); if( $timer&gt;$current){sleep(1);} else{$done=1;} } </code></pre> <p>Option 2:</p> <p>Simply remove the sleep from above my non sever knowledge thinks this is worse but, I'm sure I could be very wrong</p> <pre><code>else{ $current = time(); if( $timer&gt;$current){} else{$done=1;} } </code></pre> <p>Option 3: is to have the client ask for the page in a loop and have the file simply present the info</p> <pre><code>$result = mysqli_query($mysqli,$query); $row_cnt = mysqli_num_rows($result); if ($row_cnt&gt;0){ $row = mysqli_fetch_array($result); print $row[0]; </code></pre> <p>So which is best given My goals:</p> <ul> <li>reliability-Most importance</li> <li>speed which client gets info</li> <li>scalability - lowest importance(still important)</li> </ul> <p>Please give me a why I really want to understand a claim that one method is superior </p> <p>If this gets marked as debatable it must mean all answers are valid :) and I'll take that as an answer :) </p>
    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.
 

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