note 101026 added to function.file-get-contents
| From: | KrisWebDev at osu1 dot php dot net | Date: | Sun, 21 Nov 2010 21:17:28 +0000 |
| Subject: | note 101026 added to function.file-get-contents | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-174237@lists.php.net to get a copy of this message | ||
If your file_get_contents freezes during several seconds, here is maybe your answer:
Beware that the default keepalive timeout of Apache 2.0 httpd is 15 seconds. This is true for
HTTP/1.1 connections, which is not the default behavior of file_get_contents but you can force it,
especially if you are trying to act as a web browser. I don't know if this is also the case for
HTTP/1.0 connections.
Forcing the server to close the connection would make you gain those 15 seconds in your script:
$context = stream_context_create(array('http' =>
array('header'=>'Connection: close')));
$content = file_get_contents("http://www.somesite.com/test.html");
Another way of resolving slowness issues is to use cURL or fsockopen. Bear in mind that contrary to
the behavior of web browsers, file_get_contents doesn't return the result when the web page is
fully downloaded (i.e. HTTP payload length = value of the response HTTP "Content-Length"
header) but when the TCP connection is closed.
I hope this behavior will change in future releases of PHP.
This has been experienced with PHP 5.3.3.
----
Server IP: 69.147.83.197
Probable Submitter: 88.165.128.79
----
Manual Page -- http://www.php.net/manual/en/function.file-get-contents.php
Edit -- https://master.php.net/note/edit/101026
Del: integrated -- https://master.php.net/note/delete/101026/integrated
Del: useless -- https://master.php.net/note/delete/101026/useless
Del: bad code -- https://master.php.net/note/delete/101026/bad+code
Del: spam -- https://master.php.net/note/delete/101026/spam
Del: non-english -- https://master.php.net/note/delete/101026/non-english
Del: in docs -- https://master.php.net/note/delete/101026/in+docs
Del: other reasons-- https://master.php.net/note/delete/101026
Reject -- https://master.php.net/note/reject/101026
Search -- https://master.php.net/manage/user-notes.php