ID:               30841
 Comment by:       1 at 1 dot mcmichaelps1 dot at dot hotmail dot dot dot
                   com
 Reported By:      ewhite at stsci dot edu
 Status:           Open
 Bug Type:         HTTP related
 Operating System: Solaris 8
 PHP Version:      5.0.2
 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------

[2004-11-19 19:14:01] 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.

------------------------------------------------------------------------

[2004-11-19 19:12:51] 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.



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=30841&edit=1

Reply via email to