Note that there are some explanatory texts on larger screens.

plurals
  1. POphp reading from the server continuously
    primarykey
    data
    text
    <p>I am trying to read from the server continuously. I am using fopensock() method. The problem that the data read only once per connection. The length of each line is 350 bits.</p> <p>This is my code:</p> <pre><code> &lt;?php $fp = fsockopen("maddress",myport, $errno, $errstr, 30); if (!$fp) { echo "$errstr ($errno)&lt;br /&gt;\n"; } else { $out = "GET / HTTP/1.1\r\n"; $out .= "Host: myaddress\r\n"; $out .= "Connection: Close\r\n\r\n"; fwrite($fp, $out); while ( ($line = fgets($fp)) !== false) { echo "$line&lt;br&gt;"; }; fclose($fp); } ?&gt; &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt; &lt;title&gt;&lt;/title&gt; &lt;script type="text/javascript"&gt; window.onload=refresh; function refresh(){ getTarget(); setTimeout("refresh();",5000); } function getTarget(){ //1-creating object for the request if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 if (window.ActiveXObject) { try { xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); } catch(e) { xmlhttp = new ActiveXObject('Microsoft.XMLHTTP'); } } //2- excute response when it is ready xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200) { document.getElementById('targetText').innerText==xmlhttp.responseText; setTimeout("getTarget();", 5000);   } } //3- send request to the server xmlhttp.open("GET","newEmptyPHPWebPage2.php",true); //4- setting header for the request xmlhttp.send(null); } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;label id="targetText"&gt;&lt;/label&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Thanks for your concern!</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. 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