Re: Need a "retry" example with file()

From: Robert Oschler (no_replies_at_fake_email_address.invalid)
Date: 11/30/03


Date: Sun, 30 Nov 2003 06:09:09 GMT


"Robert Oschler" <no_replies@fake_email_address.invalid> wrote in message
news:hLOxb.26$oe4.39119@news2.news.adelphia.net...
> I'm opening an RSS feed using the file() function with an "http://"
> hyperlink as the argument for file(). If I run the PHP page that contains
> the file() call, sometimes, fairly often in fact (%50), I get a "403:
> Forbidden" error. If I hit the Reload button one or two times the
function
> succeeds and I receive the XML document.
>
> I need an example of how to trap the error return from file() so I can
enter
> a retry loop with a 1 second wait value.
>
> Can anyone point me to a good example?
>
> BTW, I've noticed that when I enter the exact same URL I am using with the
> file() function, into the address bar on Internet Explorer 6.0, it NEVER
> returns an error message. Is IE simply hiding the error and automatically
> executing a retry? Or is it possible they are requesting the document in
a
> manner more compatibile than that used with file() (which I find hard to
> imagine). I'm wondering if this 403 error is really a 'busy' error.
>
> Thanks.
>
> --
> Robert Oschler
> http://www.dog-images.com -- Devoted to providing free info on the health,
> nutrition, and training of dogs.
>
>
"Robert Oschler" <no_replies@fake_email_address.invalid> wrote in message
news:hLOxb.26$oe4.39119@news2.news.adelphia.net...
> I'm opening an RSS feed using the file() function with an "http://"
> hyperlink as the argument for file(). If I run the PHP page that contains
> the file() call, sometimes, fairly often in fact (%50), I get a "403:
> Forbidden" error. If I hit the Reload button one or two times the
function
> succeeds and I receive the XML document.
>
> I need an example of how to trap the error return from file() so I can
enter
> a retry loop with a 1 second wait value.
>
> Can anyone point me to a good example?
>
> BTW, I've noticed that when I enter the exact same URL I am using with the
> file() function, into the address bar on Internet Explorer 6.0, it NEVER
> returns an error message. Is IE simply hiding the error and automatically
> executing a retry? Or is it possible they are requesting the document in
a
> manner more compatibile than that used with file() (which I find hard to
> imagine). I'm wondering if this 403 error is really a 'busy' error.
>
> Thanks.
>
> --
> Robert Oschler
> http://www.dog-images.com -- Devoted to providing free info on the health,
> nutrition, and training of dogs.
>

For those who end up with the same question, the solution is as follows:

I was getting warnings, not parse errors so I needed to suppress the errors
and not trap them. To suppress warning messages being produced by a
function place the '@' character in front of the function name, for example,
to suppress errors coming from the file() function:

$file_results = @file($url);

To test to see if the file() function failed, which normally would produce a
warning message, examine $file_results (or whatever your result variable is
named) for FALSE using the identity equality operator which is 3 equal
signs:

if ($file_results === FALSE)
{
    // file() function failed.
}

That's it. good luck.

-- 
Robert Oschler
http://www.dog-images.com -- Devoted to providing free info on the health,
nutrition, and training of dogs.