php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28029 HTTP request failed!
Submitted: 2004-04-16 18:32 UTC Modified: 2008-03-30 12:30 UTC
Votes:48
Avg. Score:4.6 ± 0.7
Reproduced:44 of 44 (100.0%)
Same Version:10 (22.7%)
Same OS:10 (22.7%)
From: coadmin at hostings dot pl Assigned:
Status: No Feedback Package: URL related
PHP Version: 4CVS-2004-04-16 (stable) OS: FreeBSD 4.9 and 5.2.1
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2004-04-16 18:32 UTC] coadmin at hostings dot pl
Description:
------------
PHP randomly crashes(?) and some functions couldn't open HTTP connection. I found these are bad:
getimagesize()
fopen()
fsockopen()
and others...

I checked two different servers with different hardware and different systems: FreeBSD 4.9-STABLE and FreeBSD 5.2.1-p3. I checked following PHP versions: 4.3.3, 4.3.4, 4.3.5, 4.3.6, 4.3.7-dev. All are affected. Apache version is 1.3.29. PHP is compiled as mod_php.



Reproduce code:
---------------
URL requests crashes about a few minutes to a few hours after starting apache. Apache restart is helpfull and make functions working again for next a few hours. After it is the same, next restart, works for some time, and the same... During crash others PHP functions works well.

Actual result:
--------------
Sample logs:

[1]

PHP Warning:  getimagesize(http://foo.com/image.jpg): failed to open stream: HTTP request failed! ^L?^R^A in /home/foo/public_html/index.php on line 1053

[2]

PHP Warning:  fopen(http://foo.com/check.php?id=111&code=xxx): failed to open stream: HTTP request failed! @??^L in /home/foo/public_html/check.php on line 19

[3]

PHP Warning:  copy(http://foo.com/file.php?board=2700&zip=1): failed to open stream: HTTP request failed! ^LpL?^K in
 /home/foo/public_html/zip.php on line 44

And many others... I'm always receiving strange code after the "HTTP request failed!" info.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-04-16 22:05 UTC] sniper@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc.

If possible, make the script source available online and provide
an URL to it here. Try avoid embedding huge scripts into the report.

And also a GDB backtrace of the crash. (configure with --enable-debug!)

 [2004-04-17 19:15 UTC] coadmin at hostings dot pl
It's code of PHP script which make error [2].

$check is delivered by POST method from HTML form.

sprawdz.php:

<?
$id = 1111;
$code = "x,x,x,x,x";
$type = "sms,c1";

$handle = fopen("http://allpay.pl/check_code.php?id=".$id."&code=".$code."&c
heck=".$check."&type=".$type."", 'r');
$status = fgets($handle, 8);
$czas_zycia = fgets($handle, 24);
fclose($handle);
$czas_zycia = rtrim($czas_zycia);
if ($status == 0) {print "pass is bad - try again"; exit;}      else
{  # if pass is good:
if (!isset($_COOKIE['ActiveCode']))
{
setcookie('ActiveCode',1, time()+$czas_zycia);
}
else
{
setcookie('ActiveCode',0, time()+2, "/");
setcookie('ActiveCode',1, time()+$czas_zycia, "/");
}
header("Location: index1.php");
}
?>


full error:

Warning: fopen(http://allpay.pl/check_code.php?id=1111&code=x,x,x,x,x&check=yourpassword8&type=sms,c1): failed to open stream: HTTP request failed! Ae?W in /home/prospl/public_html/sprawdz.php on line 20
Warning: fgets(): supplied argument is not a valid stream resource in /home/prospl/public_html/sprawdz.php on line 21
Warning: fgets(): supplied argument is not a valid stream resource in /home/prospl/public_html/sprawdz.php on line 22
Warning: fclose(): supplied argument is not a valid stream resource in /home/prospl/public_html/sprawdz.php on line 23


line in error (20) is: "$handle = fopen("http://......"

Online URL: http://www.pros.pl/ (it is working now)

Form is from the left side with button "Wchodze do bazy". You could give any password there. It should shows "Kod niepoprawny - wpisz ponownie." - it means bad password. If fails, is timeout and it shows error message as above.

IMHO, there aren't any mistakes in php code, the problem is to open sockets with "http://" url.

I'll provide GDB backtrace asap. I'm not sure if it will be possible, because PHP still works, and there aren't any crashes. Crash was my word to describe that these functions stopped to work.
 [2004-04-18 00:59 UTC] coadmin at hostings dot pl
Maybe, old one was unclear, this the easiest way to reproduce this bug:

<?
if (fopen("http://www.cnn.com",r)) echo "OK";
?>

Online url: http://69.93.217.178/test.php

If fails it shows:
Warning: fopen(http://www.cnn.com): failed to open stream: HTTP request failed!  in /home/homepage/public_html/test.php on line 2

If works shows:
OK

Please help. Best regards.
 [2004-04-21 07:51 UTC] coadmin at hostings dot pl
Latest stable PHP from CVS wasn't helpful for me, but is difference...

Apr 21 01:48:37 gw kernel: pid 44845 (httpd), uid 65534: exited on signal 11
Apr 21 01:48:37 gw kernel: pid 45103 (httpd), uid 65534: exited on signal 11
Apr 21 01:48:38 gw kernel: pid 45391 (httpd), uid 65534: exited on signal 11
Apr 21 02:00:20 gw kernel: pid 70302 (httpd), uid 65534: exited on signal 11
Apr 21 02:13:17 gw kernel: pid 91837 (httpd), uid 65534: exited on signal 11
Apr 21 02:13:17 gw kernel: pid 80739 (httpd), uid 65534: exited on signal 11
Apr 21 02:13:18 gw kernel: pid 79870 (httpd), uid 65534: exited on signal 11
Apr 21 02:13:18 gw kernel: pid 79954 (httpd), uid 65534: exited on signal 11
Apr 21 02:13:19 gw kernel: pid 80397 (httpd), uid 65534: exited on signal 11
Apr 21 02:13:19 gw kernel: pid 92146 (httpd), uid 65534: exited on signal 11
Apr 21 02:13:19 gw kernel: pid 80029 (httpd), uid 65534: exited on signal 11
Apr 21 02:13:20 gw kernel: pid 91777 (httpd), uid 65534: exited on signal 11
Apr 21 02:13:20 gw kernel: pid 80190 (httpd), uid 65534: exited on signal 11
Apr 21 02:13:21 gw kernel: pid 80104 (httpd), uid 65534: exited on signal 11
Apr 21 02:13:21 gw kernel: pid 92057 (httpd), uid 65534: exited on signal 11

I can't do GDB because there are child processes, not root, and also I haven't httpd.core.

Now I can't see "HTTP request failed!" but document contains no data. (unexpected network error in lynx).
 [2004-04-21 09:29 UTC] derick@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

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.

We really need a backtrace.
 [2004-04-21 15:30 UTC] coadmin at hostings dot pl
Heh, the problem is *strange*...

As you reqested, I decided to compile PHP with --enable-debug. All problems went away... The aren't any segfaults and php stream releated functions works correctly all the time.

When I compile PHP again, without debug, it reproduces errors quickly...

I tried PHP-4.3.3 and 4.3.7dev - both of them works preety good with --enable-debug, and reproduce erros in not debug mode.

What's it? Other configure options are the same. In --enable-debug only Zend doesn't work, but my scripts doesn't use it.

Please help. I don't know gow to reproduce errors with --enable-debug.
 [2004-04-23 18:04 UTC] iliaa@php.net
When compiling PHP without debug do you export your own 
CFLAGS? It is possible that with debug your compiler over 
optimizes and consequently breaks the code. If you are not 
setting any optimization options, try doing export 
CFLAGS=-O before running configure/make/make install 
procedure. 
 [2004-04-29 13:53 UTC] coadmin at hostings dot pl
Hello,

I cleared my own CFLAGS and also tried to compile with exported CFLAGS=-O but problem is still recurrent.

I can't reproduce problem in --enable-debug.

I'm waiting for any other hints.
 [2004-04-29 23:04 UTC] sniper@php.net
Disable all zend extensions first..then if you still get the segfault with non-debug build, get a backtrace of THAT, it might show _something_..

 [2004-04-30 12:24 UTC] bwb at bweebhosting dot com
I am having this problem as well. The interesting thing is that if I run:

<?
if (fopen("http://www.cnn.com",r)) echo "OK";
?>

Through a shell as root it works fine and returns ok, as well if I have fopen open a local file. Through my web browser using it to open a local file works as well and its only when its trying to open an outside connection that it hangs. 

This seems to indicate its a run/permission problem with apache maybe?

Thanks, Ben W.
 [2004-05-05 13:45 UTC] coadmin at hostings dot pl
How to build without Zend Optimizer and others?

Now I'm using:
./configure --with-apxs=/usr/local/apache/bin/apxs --with-xml --enable-bcmath --enable-calendar --with-curl --enable-ftp --with-gd --with-jpeg-dir=/usr/local --with-png-dir=/usr --with-xpm-dir=/usr/X11R6 --enable-magic-quote --with-mysql --enable-discard-path --with-pear --enable-sockets --enable-track-vars --enable-versioning --with-zlib

and it goes with Zend Optimizer like here:
http://69.93.217.178/info.php
 [2004-05-05 15:55 UTC] edink@php.net
By removing or commenting out all zend_extension= lines from /usr/local/Zend/etc/php.ini and restarting apache.
 [2004-05-05 16:18 UTC] coadmin at hostings dot pl
After commenting out Zend in php.ini, Zend Optimizer went down and phpinfo() was right, without Zend Opt, but my problem isn't solved. I reproduced bug in 15 minutes. 

So, only one way to prevent bug is --enable-debug in PHP.

I'm waiting for other hints.
 [2004-05-05 16:23 UTC] coadmin at hostings dot pl
One more thing: now I haven't segfaults. I don't know how to  reproduce segfaults, somethimes there are with HTTP request failed, sometimes not. Now not.
 [2004-05-05 22:21 UTC] sniper@php.net
Remove --enable-versioning from your configure line for starters. 
 [2004-05-06 09:13 UTC] coadmin at hostings dot pl
The same problem reproduced in a few hours.
 [2004-05-06 23:28 UTC] bwb at bweebhosting dot com
I was having this problem and found someone who can fix it. Email adrian@psoft.biz and he can, he fixed it and mine is working fine as of last night.
 [2004-05-09 11:35 UTC] coadmin at hostings dot pl
I'm still waiting for solution from PHP team.
 [2004-05-24 04:16 UTC] joseph at xtremecorponline dot com
Hello -
Running FreeBSD 4.9,PHP4.3.6.  

I get the same errors, fopen causing segmentation fault, which then interrupts the browser's SSL connection. I have a script that thumbnails images on the fly.  It's not all the time, but every once in a while, fopen will cause this error:

 [error] PHP Warning:  fopen: failed to open stream: HTTP
 in /usr/local/www/site/phpthumb.php on line 615  

which is reported in my apache error log for the virtual host.  consequently, immediately after, in the apache error-log in apache root, this error occurs:

 child pid 43187 exit signal Segmentation fault (11)  (note the PID # is always different as the apache processes recycle)


The script file is 1200 lines long, I'm sure yuo dont want it all, but here is the area of line 615 as the error shows.  The code `if ($fp = fopen($_REQUEST['src'], 'rb')) {` is line 615.

FreeBSD 4.9
Apache/1.3.29 
PHP/4.3.6
mod_ssl/2.8.16 
OpenSSL/0.9.6g

Am also running turck-mmcache 2.4.6

Please help with this.  Am also more than willing to get you any info you need to help troubleshoot as fast as possible.

<?php
		ob_start();
		if ($fp = fopen($_REQUEST['src'], 'rb')) {

			$OriginalImageData = '';
			do {
				$buffer = fread($fp, 8192);
				if (strlen($buffer) == 0) {
					break;
				}
				$OriginalImageData .= $buffer;
			} while (true);
			fclose($fp);

		} else {

			$fopen_error = ob_get_contents();
			ob_end_clean();
			if (ini_get('allow_url_fopen')) {
				ErrorImage('cannot open "'.$_REQUEST['src'].'" - fopen() said: "'.$fopen_error.'"');
			} else {
				ErrorImage('"allow_url_fopen" disabled');
			}

		}
		ob_end_clean();
?>
 [2004-05-24 04:25 UTC] joseph at xtremecorponline dot com
My mistake.  fopen causes these errors when the filename passed to it does not exist, or is corrupted, on the server.  I hope that helps narrow it down.
 [2004-07-11 22:01 UTC] sniper@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php4-STABLE-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php4-win32-STABLE-latest.zip

And use EXACTLY this configure line:

# ./configure --with-apxs=/usr/local/apache/bin/apxs --disable-all
# make && make install
# /usr/local/apache/bin/apachectl stop && sleep 10
# /usr/local/apache/bin/apachectl start

Then test using the simplest script you could reproduce this problem before.

 [2004-07-19 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2004-07-25 14:02 UTC] coadmin at hostings dot pl
Hello,

sorry I couldn't use --disable-all on productive machine. There are too many commercial hostings accounts.

But...

My problem was suddenly  resolved  about month ago before compiling PHP. It was very strange. I didn't do any changes in Apache or PHP. From one day up to now all is working correctly. There wasn't any HTTP request failed!. Additionaly, I upgraded to 4.3.8 a week ago and there is many many many less segfaults.

But... #2

On the other server (php 4.3.6) always was OK. After upgrade to PHP 4.3.8 I've again the same bug...

I really don't know what is it. Maybe it's OS releated? But as I see on bug status, only 37.5% people, reproducting this bug has the same OS as me.

There aren't segaults during HTTP request failed!, but there are other segfaults releated to php engine.
 [2004-08-18 08:58 UTC] andreizilla at gmail dot com
I'm having simular (same?) problems on:

* FreeBSD zig.andreib.com 5.2.1-RELEASE-p9 FreeBSD 5.2.1-RELEASE-p9 #0: Sun Aug 15 18:42:43 CDT 2004     root@zig.andreib.com:/usr/obj/usr/src/sys/MYKERNEL  i386
* Apache/1.3.31
* PHP Version 4.3.8 configuted with: './configure' '--enable-versioning' '--enable-memory-limit' '--with-layout=GNU' '--with-config-file-scan-dir=/usr/local/etc/php' '--disable-all' '--with-regex=php' '--disable-cli' '--with-apxs=/usr/local/sbin/apxs' '--disable-ipv6' '--prefix=/usr/local' 'i386-portbld-freebsd5.2.1'

Apache seems to be segfaulting every several minutes. This is what the log files look like:

[Wed Aug 18 01:52:25 2004] [notice] child pid 18870 exit signal Segmentation fault (11)
[Wed Aug 18 01:52:28 2004] [notice] child pid 18869 exit signal Segmentation fault (11)
[Wed Aug 18 01:52:32 2004] [notice] child pid 18868 exit signal Segmentation fault (11)
[Wed Aug 18 01:52:45 2004] [notice] child pid 18867 exit signal Segmentation fault (11)
[Wed Aug 18 01:53:15 2004] [notice] child pid 18866 exit signal Segmentation fault (11)

... times several hundred.

This also happends when I do `apachectl graceful'

If anyone knows where I can find more information on resolving this problem please, please, please tell me. Thank you.

- andrei
 [2004-09-02 00:02 UTC] maximander at gmail dot com
this has been happening to my site too.
the following code errors, as does almost any use of file(),fopen(),file_get_contents() or readfile() on remote files. fsockopen seems to work for now though.

<?
// error'ing code
$file = file("http://gerpok.darkflux.com/write.php");
if(strpos($file[0],"you don't")) { echo "not updated";}
?>

and, whats more, after a recompile with --enable-debug, it is still error'ing. anything useful we can do with a debug build that errors on a regular basis?
 [2004-10-08 01:02 UTC] joseph at digiweb dot net dot nz
Apache 2.0.46
PHP 4.3.2
Redhat Enterprise 3.0

We were seeing very similar behaviour to this with fopen, getimagesize, etc, however, we were not experiencing any segfaults.

What we found was that first, the number of VirtualHosts we had defined would affect the behaviour of this bug: If we had more than 502 virtualhosts, the fopen HTTP requests would fail, if we had 502 or less, they would work correctly.

We thought it might have something to do with the number of open file handles, but as far as we could tell, we were well clear of these limits.

Then (basically by accident) we worked out that if we had each VirtualHost use the same, global "ErrorLog" file, the problem went away, as opposed to the situation before when we had seperate error logs for each virtualhost.

We also had another test box, running Fedora Core 2, Apache 2.0.51, and PHP 5.02, on which we were unable to reproduce the problem.

I hope this might possibly shed some light on things.
 [2004-11-01 15:51 UTC] tongsam at 126 dot com
I'v this problem too, on apache started a few hours, the logs:

kernel: pid 65604 (httpd), uid 1011: exited on signal 11

Freebsd 4.9 + Apache 2.0.52 + php 4.3.9
 [2004-11-02 10:41 UTC] jorton@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5-STABLE-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.0-win32-latest.zip

If using fsockopen and friends on servers with large numbers of error logs configured and seeing memory corruption bugs or otherwise, then that's bug 24189 - select vs FD_SETSIZE issues.

This is fixed for future 5.0.x releases (all praise Wez!), so try a 5.0.x snapshot.  Bugs in Fedora Core or RHEL PHP packages should be reported to https://bugzilla.redhat.com/bugzilla/.

 [2004-11-10 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2005-02-14 21:32 UTC] maxim at enelis dot ru
Have the same problem on FreeBSD 5.3 Release. + Apache 2.0.48 or 2.0.52  + PHP 4.3.8 + 4.3.9 + 4.3.10

--enable-debug doesn't solve the problem. Using --disable-all can't be done because this is a production host. It worked without any problems until last days. And right now fopen http doesnt work at all.

Have tested the same on FreeBSD 4.9 + Apache 2.0.48 + PHP 4.3.10. Works correct with no problems.

The server where we catch this bug hosts about  500 virtualhosts. 

code:

<?
$r = fopen("http://ya.ru","r");
fpassthru($r);
fclose($r);
?>

--
error:

Warning: fopen(http://ya.ru/): failed to open stream: HTTP request failed! in /home/test/www/test2.php on line 6
--

Sometimes after "HTTP request failed!" there are some unreadable chars as "".
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Wed Feb 26 14:01:28 2020 UTC