Re: Exception handling with file()
| From: | Richard Lynch | Date: | Thu, 14 Feb 2008 20:29:46 +0000 |
| Subject: | Re: Exception handling with file() | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-269317@lists.php.net to get a copy of this message | ||
On Mon, February 11, 2008 6:34 am, John Papas wrote:
> I need to open a remote file with file() and I would like to put it
> inside a try-catch but as far as I can tell file() does not raise an
> exception if it fails. The following code:
>
> try {
> $data = file('http://myserver.com/myfile.txt');
> $date = substr($data, 0);
> } catch (Exception $e) {
> $data = "it failed";
> }
>
> echo $data;
>
> echoes a warning:
>
> Warning: file('http://myserver.com/myfile.txt')
> [function.file]:
> failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found
> in.....
Old-school PHP functions do not (and will not) raise exceptions.
Use http://php.net/set_error_handler
--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/from/lynch
Yeah, I get a buck. So?