php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30841 get_headers failing incorrectly, and not working as expected.
Submitted: 2004-11-19 19:12 UTC Modified: 2005-03-14 01:00 UTC
Votes:3
Avg. Score:4.7 ± 0.5
Reproduced:3 of 3 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: ewhite at stsci dot edu Assigned:
Status: No Feedback Package: HTTP related
PHP Version: 5.0.2 OS: Solaris 8
Private report: No CVE-ID: None
 [2004-11-19 19:12 UTC] ewhite at stsci dot edu
Description:
------------
I recently wrote a script to check my webservers every 4 minutes (run via cron) to see if they were still alive.

I opted to use get_headers to do this for simplicity.

The program looped through a config of 20+ some servers, calling get_headers on their root index page, checking for errors to come from that, and reporting if the server did not respond.

get_headers then proceeded to show problems with this.  Unfortunately these problems were not consistant, nor directly repeatable, yet did in fact happen every hour or so at random intervals when the script ran.

The problems that surfaced were:

A) At times, get_headers would exit, failed, and $php_errormsg would contain: Connection still in progress.  This should only occur on a non-blocking request, and get_headers should be blocking.

B) Also at times, it would fail, and errormsg would be: "HTTP request failed!" ... Yet looking at the server logs, the request was handled and finished correctly.

C) Similarly, on one particular website that had a redirect on it's homepage, instead of completely successfully with a 301 response, it again failed, and errormsg was: "HTTP request failed! HTTP/1.1 301 Moved Permanently"

All of these errors would not happen every time the script ran, but just 'sometimes'.  Yet regularly enough to fill my mailbox with false website errors.

Recoding my script later to use Net_HTTP_Client, which I would have used in the first place if not for the handy existance of get_headers, now works perfectly fine.

While I'm reporting this, I would like to add another problem, and a 'using it' problem:

P1) It's get_headers, yet it is making a full GET / request instead of a HEAD / request.  Not expected functionality, and overkill there.

P2) Just for the using of the function, it would be nice if it had an easier way of returning some of the error codes.  Since get_headers() actually FAILS in there is a 403, or 401.  I would prefer myself that it still exited normally, with the headers that were in fact sent back, and I can parse the 401/403 info from the array.  The request didn't really fail, it just returned a 401, that may have been (and was in this case) what I wanted.   Therefore, I had to write in the code that if there was an error (false was returned), that I then had to scan the $php_errormsg to see if a 401 or 403 was returned, in which case it actually did work.
   IMO, if the server returns properly, get_headers should return the headers that were given.  Not fail and flag it in errormsg.

Reproduce code:
---------------
$out = @get_headers("http://web.site.com:80/");

However, as stated, run this in a script on 20+ servers in a row, and run it every 4 minutes.

Expected result:
----------------
I expect it to properly contact the server, and return the headers.  Not error when it was actually a completed request.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-11-19 19:14 UTC] ewhite at stsci dot edu
Just realized I forgot to mention.

This was being run via command-line php of course.  triggered from the cron job.
 [2005-01-25 15:48 UTC] 1 at 1 dot mcmichaelps1 dot at dot hotmail dot dot dot com
I have encountered a very similar bug in php 5.0.1 on Windows 2000 running IIS 5.0 - using the pre-compiled binaries and php configured through ISAPI.
 [2005-03-06 19:12 UTC] sniper@php.net
Please try using this CVS snapshot:

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


 [2005-03-14 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".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Oct 04 18:01:29 2024 UTC