php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44954 file_get_contents crashes Apache
Submitted: 2008-05-09 11:22 UTC Modified: 2009-02-18 08:40 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: abakker at gmx dot net Assigned:
Status: Not a bug Package: Reproducible crash
PHP Version: 5.2.8 OS: win32 only - Win XP
Private report: No CVE-ID: None
 [2008-05-09 11:22 UTC] abakker at gmx dot net
Description:
------------
Apache crashes if a lot of file_get_contents are done. The Apache error.log only contains this (I guess this just confirms that the Apache server has crashed and no longer responds): [Fri May 09 12:15:04 2008] [error] [client 192.168.0.1] PHP Warning: 
file_get_contents(http://localhost/test.htm) [<a href='function.file-get-contents'>function.file-get-contents</a>]: failed to open stream: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.\r\n in C:\\Andre\\Apache\\test.php on line 6


Reproduce code:
---------------
The following PHP script reproduces the problem:

<?php
echo '<pre>';
for ($i=1;;$i++)
{ echo $i."\n";
  flush();ob_flush();
  $contents = file_get_contents('http://localhost/test.htm');
}
?>

After 203 iterations the Apache server crashes. The result is the same whether localhost or IP address is used.

The problem depends on the contents of the test.htm file. If it only contains

<html>
<body>
</body>
</html>

the script runs until it reaches the max execution time.

The test.htm that reproduces the problem contains:

<html>
<head>
<link rel="stylesheet" href="/systeem/style/style.css">
<title>V.V. De Meern</title>
<meta name="description" content="V.V. De Meern">
<meta name="robots" content="index,follow">
<script src="/beheer/include/header.js"></script>
</head>
<body>
<script src="menu.js"></script>
<a href="menu.html"></a>
<h1>Home pagina A1</h1>
<p><img src="a1.jpg" border="0" alt="" /></p>
<h1>Spelers</h1>
<p>Nicky Vermeulen, Jon Gruters, Jerryl Smeenk, Bram van Wiggen, Rolf van
Elderen, Sander van der Woude, Melvin van Nood, Jorgos Katsivilis, Leo
Wakelkamp, Chen Margolin, Luis Plein, Danny Berkhouwer, Whaheed Khodabaks,
Alessandro Damen, Thomas van Amerongen</p>
<h1>Leiders</h1>
<p>John Dunsbergen, Joost Satink, Lex van der Woude</p>
<script src="/beheer/include/footer.js"></script>
</body>
</html>

Expected result:
----------------
Run until max execution time exceeded.

Actual result:
--------------
Crashed beforehand.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-05-10 23:01 UTC] jani@php.net
Are you sure it's a crash? If so, it's might be PHP that is crashs so where's the backtrace? And did you check the Apache logs for any possible information about this issue..?

Instructions how to get a backtrace under Windows:
http://bugs.php.net/bugs-generating-backtrace-win32.php 

 [2008-05-10 23:02 UTC] jani@php.net
Nevermind the Apache log question..of course you checked that. :) But there's no indication that anything crashed anywhere..
 [2008-05-11 11:15 UTC] abakker at gmx dot net
In the Apache error log it just says the connected party failed to respond (the complete message is in the beginning of this bug report).

I tried the backtrace tools, but did not manage to get a backtrace. I looked at the processes. I have two httpd.exe processes when I start Apache. When I reproduce the problem, the two processes remain. I guess technically this means the Apache server does not crash, but hangs and this is the reason why I do not get a backtrace?

Anyway, the two httpd.exe processes keep on running, but any web page request fails (internet explorer displays the standard page that it could not access the requested web page). Apache no longer seems to respond to requests. The two httpd.exe processes use no cpu when the problem occurs.

A restart of Apache does not give any error message, but does not solve the issue. A stop and start is needed. Not sure whether this tells you something.

Anyway, were you able to reproduce the problem yourself? That would be helpful, if so, you could do any backtracing or other diagnosis yourself. I am not familiar with the diagnostic tools, it would be much better if you could do it.
 [2008-05-18 00:20 UTC] jani@php.net
I really doubt this is any bug in PHP anyway. You propably just run out of Apache threads/childs with that script that doesn't really give Apache any chance. Try adding some 'sleep(1);' line inside the for() loop.
 [2008-05-18 08:43 UTC] abakker at gmx dot net
I added a sleep(1) and set max_execution_time to 999. After 172 iterations the Apache server hangs (does not respond to page requests anymore). The script continues very slowly at this point, it times out on every file_get_contents request (in the error log you see the error message mentioned at the top of this bug report for every iteration).

The total number of threads in Windows Task Manager does not increase when running the script. My system is also not running out of resources, I have 3 Gb memory of which 2.6 Gb is available.

When you replace file_get_contents with http_get or curl_exec the problem does not occur. Seems to me that this indicates that there is something wrong with file_get_contents.

In any case a PHP script should not cause the Apache server to hang/crash (Apache does not respond to page requests for any user anymore) and bring a production system down.
 [2008-07-14 21:13 UTC] jani@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a backtrace to see what is happening behind the scenes. To
find out how to generate a backtrace, please read
http://bugs.php.net/bugs-generating-backtrace.php for *NIX and
http://bugs.php.net/bugs-generating-backtrace-win32.php for Win32

Once you have generated a backtrace, please submit it to this bug
report and change the status back to "Open". Thank you for helping
us make PHP better.


 [2008-07-24 09:10 UTC] abakker at gmx dot net
I tried to create a backtrace for the httpd.exe process, but no dmp file is generated. Either Apache does not crash (but hangs) or I am doing something wrong.

The problem can easily be reproduced (just run the script I provided). I suggest you reproduce the problem yourself which allows you to do whatever analysis or backtracing you need. That would be far more efficient than passing it back to me.
 [2008-08-07 22:15 UTC] jani@php.net
The problem is that I can't reproduce this. So it's up to you either provide the backtrace or just let this report rot.
 [2009-01-20 08:23 UTC] abakker at gmx dot net
I completely removed Apache and PHP from my PC and did a fresh default install of Apache 2.2.11 and PHP 5.2.8 (on my PC with Windows XP Pro). The problem still occurs. After 202 iterations of file_get_contents the script continues very slowly, every iteration takes 1 minute. In the Apache error log file the following entries are created:

[Tue Jan 20 09:09:17 2009] [error] [client 127.0.0.1] PHP Warning:  file_get_contents(http://localhost/bugs/bug.htm) [<a href='function.file-get-contents'>function.file-get-contents</a>]: failed to open stream: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.\r\n in C:\\Andre\\Apache\\public_html\\bugs\\bug.php on line 7

[Tue Jan 20 09:10:17 2009] [error] [client 127.0.0.1] PHP Warning:  file_get_contents(http://localhost/bugs/bug.htm) [<a href='function.file-get-contents'>function.file-get-contents</a>]: failed to open stream: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.\r\n in C:\\Andre\\Apache\\public_html\\bugs\\bug.php on line 7

[Tue Jan 20 09:11:17 2009] [error] [client 127.0.0.1] PHP Warning:  file_get_contents(http://localhost/bugs/bug.htm) [<a href='function.file-get-contents'>function.file-get-contents</a>]: failed to open stream: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.\r\n in C:\\Andre\\Apache\\public_html\\bugs\\bug.php on line 7

Apache does not respond to page requests in other sessions, i.e. other users cannot access web pages anymore.

I guess technically speaking Apache does not crash, but hangs. Maybe that is why I am unable to create a backtrace. Anyway, the problem occurs with a default install of Apache and PHP. Maybe you are able to reproduce the problem if you do a default install on your PC.
 [2009-01-21 19:30 UTC] jani@php.net
I can not reproduce this on real OS. Assuming it's win32 only issue.
 [2009-02-17 18:47 UTC] pajoye@php.net
It is not a crash but a timeout during the connection for whatever reasons.

There is no bug here.
 [2009-02-18 08:40 UTC] abakker at gmx dot net
Bug or not, it is a nasty problem because the Apache server stops responding to requests from any user. It would be nice if someone would figure out what goes wrong (and how to avoid that).
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Jul 04 14:01:35 2025 UTC