From:             ewhite at stsci dot edu
Operating system: Solaris 8
PHP version:      5.0.2
PHP Bug Type:     HTTP related
Bug description:  get_headers failing incorrectly, and not working as expected.

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.


-- 
Edit bug report at http://bugs.php.net/?id=30841&edit=1
-- 
Try a CVS snapshot (php4):   http://bugs.php.net/fix.php?id=30841&r=trysnapshot4
Try a CVS snapshot (php5.0): 
http://bugs.php.net/fix.php?id=30841&r=trysnapshot50
Try a CVS snapshot (php5.1): 
http://bugs.php.net/fix.php?id=30841&r=trysnapshot51
Fixed in CVS:                http://bugs.php.net/fix.php?id=30841&r=fixedcvs
Fixed in release:            http://bugs.php.net/fix.php?id=30841&r=alreadyfixed
Need backtrace:              http://bugs.php.net/fix.php?id=30841&r=needtrace
Need Reproduce Script:       http://bugs.php.net/fix.php?id=30841&r=needscript
Try newer version:           http://bugs.php.net/fix.php?id=30841&r=oldversion
Not developer issue:         http://bugs.php.net/fix.php?id=30841&r=support
Expected behavior:           http://bugs.php.net/fix.php?id=30841&r=notwrong
Not enough info:             
http://bugs.php.net/fix.php?id=30841&r=notenoughinfo
Submitted twice:             
http://bugs.php.net/fix.php?id=30841&r=submittedtwice
register_globals:            http://bugs.php.net/fix.php?id=30841&r=globals
PHP 3 support discontinued:  http://bugs.php.net/fix.php?id=30841&r=php3
Daylight Savings:            http://bugs.php.net/fix.php?id=30841&r=dst
IIS Stability:               http://bugs.php.net/fix.php?id=30841&r=isapi
Install GNU Sed:             http://bugs.php.net/fix.php?id=30841&r=gnused
Floating point limitations:  http://bugs.php.net/fix.php?id=30841&r=float
MySQL Configuration Error:   http://bugs.php.net/fix.php?id=30841&r=mysqlcfg

Reply via email to