Re: file_get_contents for URLs?
| From: | Richard Heyes | Date: | Tue, 07 Apr 2009 16:14:19 +0000 |
| Subject: | Re: file_get_contents for URLs? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-291186@lists.php.net to get a copy of this message | ||
> Hey all,
Hello.
> I'm doing some maintenance work on an existing system and there is a piece
> of code that uses file_get_contents() to read data from a URL, which is fine
> in theory I suppose.
>
> But the problem is sometimes the server where that URL lives is not
> available, and the system hangs indefinitely.
>
> Shouldn't this be done with curl, and if so can it be done so that the call
> will time out and return control back when the server is not available?
Looking at the docs alone, it looks like you can pass a stream as the
third argument to file_get_contents(). So create a stream, set the
timeout on that (using stream_context_create() &
stream_context_set_option() ), and then pass it to
file_get_contents().
--
Richard Heyes
HTML5 Canvas graphing for Firefox, Chrome, Opera and Safari:
http://www.rgraph.net (Updated March 28th)