stream_get_contents doesn’t seem to handle persistent (KeepAlive) connections correctly. It waits for the connection to timeout before returning. Apache 2.2 has a KeepAliveTimeout of 5 seconds by default. Is there anything I can do about this? (Aside from disabling KeepAlive on the server, or using protocol_version 1.0)
$opts = array('http' =>
array(
'method' => 'GET',
'protocol_version' => 1.1,
)
);
$context = stream_context_create($opts);
$stream = fopen('http://google.com', 'r', false, $context);
$metadata = stream_get_meta_data($stream);
$data = stream_get_contents($stream);
fclose($stream);
Thanks.
Connection: closetells the server not to use a persistent connection and to drop the TCP connection after the response has been sent.This is part of the HTTP/1.1 standard, and as the PHP manual says: