Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You could take a look at the <a href="http://php.net/manual/en/function.flush.php" rel="nofollow">flush() function</a></p> <p>"Flushes the write buffers of PHP and whatever backend PHP is using (CGI, a web server, etc). This attempts to push current output all the way to the browser with a few caveats."</p> <p>You probably also have to call <code>ob_flush;</code> So if you put the following on strategic places it should work:</p> <pre><code>echo "something"; flush(); ob_flush(); </code></pre> <p>You can let PHP run infinite with <code>set_time_limit(0)</code>. See the <a href="http://php.net/manual/en/function.set-time-limit.php" rel="nofollow">PHP Manual</a>. So put this line on top of your php file.</p> <p>Also check out the <code>default_socket_timeout</code> setting if you have problems after 60 seconds.</p> <p><strong>Edit</strong>: Running the script here now for 30 minutes without a problem. Even httpd cpu is low now. (due to the usleep i think)</p> <p>My working code:</p> <pre><code>&lt;? error_reporting(E_ALL); ini_set('display_errors', '1'); set_time_limit(0); ob_start(); function flush_buffers(){ ob_end_flush(); ob_flush(); flush(); ob_start(); } echo date("d-m-Y H:i:s"); ?&gt; &lt;body style="background-color: yellow;"&gt; &lt;div style="margin: auto; margin-top: 50px;"&gt; &lt;div style="margin: auto; width: 200px; font-weight: bold; font-size: 20px; margin-bottom: 20px; color: darkgreen;"&gt;Real Time View&lt;/div&gt; &lt;?php //Create a UDP socket if(!($socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP))) { $errorcode = socket_last_error(); $errormsg = socket_strerror($errorcode); die("Couldn't create socket: [$errorcode] $errormsg \n"); } echo "Socket created &lt;br&gt;"; flush_buffers(); if( !socket_set_nonblock($socket) ){ $errorcode = socket_last_error(); $errormsg = socket_strerror($errorcode); die("Could not nonblock socket : [$errorcode] $errormsg \n"); } // Bind the source address if( !socket_bind($socket, "0.0.0.0" , 9999) ){ $errorcode = socket_last_error(); $errormsg = socket_strerror($errorcode); die("Could not bind socket : [$errorcode] $errormsg \n"); } echo "Socket bind OK &lt;br&gt;"; flush_buffers(); socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array("sec"=&gt;1, "usec"=&gt;100)); socket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO, array("sec"=&gt;1, "usec"=&gt;100)); try { while(1){ usleep(0.5 * 1000000); // 0.5 seconds if (False === ($r = socket_read($socket, 1024))) { $errorcode = socket_last_error(); $errormsg = socket_strerror($errorcode); if ($errorcode!='11') { echo "error reading : [$errorcode] $errormsg &lt;br&gt;\n"; } } echo $r; if ($r!='') { echo ".&lt;br&gt;"; } flush_buffers(); } } finally { socket_close($socket); } ?&gt; &lt;/div&gt; &lt;/body&gt; &lt;? ob_end_flush(); ?&gt; </code></pre>
    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