|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2003-02-19 09:10 UTC] sp at m-me dot dk
When using the function file() or file_get_contents() added in PHP 4.3.0 I have a problem when I try to read a URL instead of reading directly from the filesystem.
This works fine:
file("test.txt");
This creates an "Internal Server Error" the webserver:
file("http://localhost/test.txt");
I've testet this on 3 different systems:
System 1:
----------------------------------------
Windows XP Pro sp1
Apache 2.0.43
PHP 4.3.1
System 2:
----------------------------------------
Windows 2000 Server (build 5002195) sp3
Apache 2.0.43
PHP 4.3.0
System 3:
----------------------------------------
Linux 2.4.20
Apache 1.3.27
PHP 4.3.1
This is what happend on the 3 systems:
System 1:
----------------------------------------
The browser is loading for about 5 minutes (more than the the maximum PHP execution time!?) then displays an "Internal Server Error" and writes this in the webserver error log:
[Wed Feb 19 14:54:40 2003] [error] [client 127.0.0.1] Premature end of script headers: php.exe, referer: http://localhost/test/readfile/
System 2:
----------------------------------------
The browser is loading for 30 sec. (the maximum PHP execution time) and then displays this in the browser:
Fatal error: Maximum execution time of 30 seconds exceeded in
C:\data\htdocs\fil1.php on line 3
and this in the webserver error log:
[Wed Feb 19 15:32:41 2003] [error] [client 127.0.0.1] Premature end of script headers: php.exe, referer: http://localhost/
System 3:
----------------------------------------
On the this system (the Linux system) both examples worked without any errors. Besides the operating system the biggest difference between the other systems and this one is the Apache version. Could it be Apache 2.x vs. PHP 4.3.x that was the problem?
/watson
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 06:00:02 2025 UTC |
Your system has determined two alternative addresses to attempt to contact for localhost and it attempts each alternative for default_socket_timeout in seconds. For some reason it is not connecting successfully. Please try the following script: <?php set_time_limit(600); ini_set('default_socket_timeout', 5); $x = file("http://localhost/test.txt"); var_dump($x); var_dump($http_response_header); ?> and report back here. It would also help if you could try fetching the same url using: curl -i http://localhost/test.txt and paste the output here.The script supplied gives the right output, but still takes "default_socket_timeout * 2" seconds. I found that if I removed the first line "set_time_limit(600);" the script faild again - Still I could not get rid of the long timeout. The output from the code was: -------------------------------------------------- array(1) { [0]=> string(6) "foobar" } array(9) { [0]=> string(15) "HTTP/1.1 200 OK" [1]=> string(35) "Date: Fri, 21 Feb 2003 00:43:31 GMT" [2]=> string(29) "Server: Apache/2.0.43 (Win32)" [3]=> string(44) "Last-Modified: Tue, 18 Feb 2003 15:48:22 GMT" [4]=> string(23) "ETag: "37a6-6-d5528ab3"" [5]=> string(20) "Accept-Ranges: bytes" [6]=> string(17) "Content-Length: 6" [7]=> string(17) "Connection: close" [8]=> string(44) "Content-Type: text/plain; charset=ISO-8859-1" } -------------------------------------------------- The output from the curl command (had to install Cygwin) was: -------------------------------------------------- $ curl -i http://localhost/test/readfile/test.txt HTTP/1.1 200 OK Date: Fri, 21 Feb 2003 00:41:16 GMT Server: Apache/2.0.43 (Win32) Last-Modified: Tue, 18 Feb 2003 15:48:22 GMT ETag: "37a6-6-d5528ab3" Accept-Ranges: bytes Content-Length: 6 Content-Type: text/plain; charset=ISO-8859-1 foobar --------------------------------------------------Could you also paste the output of this script: <?php var_dump(gethostbynamel("localhost")); ?>Using 127.0.0.1 instead of localhost had no effect. The script still took "2 * default_socket_timeout" seconds. The var_dump(gethostbynamel("localhost")); returned (with no delay): -------------------------------------------------------- array(1) { [0]=> string(9) "127.0.0.1" } --------------------------------------------------------