Page 1 of 1
Error checking for file_get_contents
Posted: Tue Jun 12, 2007 8:40 pm
by realtime158
I was wondering if there is a way so that if file_get_contents has a problem reading a URL page that it will not crash the php script. So like on error just continue or skip. I am using PHP 4.4.4
Thanks...
Posted: Tue Jun 12, 2007 8:58 pm
by feyd
Last I checked,
file_get_contents() outputs a warning upon encountering problems. This does not stop execution.
Posted: Tue Jun 12, 2007 9:39 pm
by Benjamin
Per the manual you can set the timeout value..
Code: Select all
ini_set('default_socket_timeout', 120);
But I'd recommend you just use curl instead.
Posted: Tue Jun 12, 2007 11:14 pm
by aaronhall
Check with file_exists() prior to calling file_get_contents()
Posted: Tue Jun 12, 2007 11:19 pm
by feyd
Note:
file_exists() only supports URLs in PHP 5+.
Edit: However, user comments on the page supply potential url_exists() functions that work similarly. Some do require PHP 5, so be careful.
Posted: Tue Jun 12, 2007 11:30 pm
by aaronhall
eek, didn't know that, thanks