Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Keep-alive connections</strong></p> <p>Normally, if a connection isn't set as <code>keep-alive</code>, once PHP terminates the current script, the remaining output buffer gets forwarded to the web-server, which in turn forwards the data to the client. Then the web-server <strong>closes its connection</strong> to the client (browser).</p> <p>If you request </p> <pre><code>Connection: keep-alive </code></pre> <p>the server does just this: It <strong>keeps the connection open</strong>, even if a reply has completely finished. Thus, the mentioned behavior is just fine. <strong>Furthermore, e.g. <code>feof()</code> won't return FALSE - since more data might arrive eventually.</strong></p> <p>Note, that you can re-use the keep-alive connection within your currently running PHP script. But once your PHP script finishes, the keep-alive connection will be disconnected.</p> <p>Thus, you <strong>can't reuse</strong> the keep-alive connection using your next PHP script instance.</p> <p><strong>Case 1 - Amount of data known before request</strong></p> <p>If you know the amount of data beforehand, you might read just that amount of data <code>$expectedAmountOfDataInBytes</code> and then close the connection:</p> <pre><code>$expectedAmountOfDataInBytes = 2023; $handle = fopen( "http://www.stackoverflow.com/", "r" ); if ( ! is_resource( $handle )) { echo 'sorry'; exit; } while( ( ! feof( $handle ) ) &amp;&amp; ( 0 &lt; $expectedAmountOfDataInBytes-- ) ) { $contents .= fread( $handle, 1 ); } fclose($handle); </code></pre> <p><strong>Case 2 - Amount of data unknown before request</strong></p> <p>In case you don't know the amount of data beforehand, you need to submit a <a href="https://de.wikipedia.org/wiki/Hypertext_Transfer_Protocol" rel="nofollow">HTTP</a> request</p> <pre><code>GET /infotext.html HTTP/1.1 Host: www.example.net </code></pre> <p>and parse an answer like so:</p> <pre><code>HTTP/1.1 200 OK Server: Apache/1.3.29 (Unix) PHP/4.3.4 Content-Length: 4 Content-Language: de (nach RFC 3282 sowie RFC 1766) Connection: close Content-Type: text/html ABCD </code></pre> <p>Find in the <a href="http://www.php.net/manual/en/sockets.examples.php" rel="nofollow">PHP Manuals</a> a simple HTTP client based on <a href="http://www.php.net/manual/en/book.sockets.php" rel="nofollow">sockets I/O</a>.</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. VO
      singulars
      1. This table or related slice is empty.
    2. 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