NYCPHP Meetup

NYPHP.org

[PHP] fsockopen() to remote URL: what if remote URL "times out"?

Maxim Maletsky maxim at php.net
Fri Jan 10 06:17:06 EST 2003


"Phil Powell" <soazine at erols.com> wrote... :

> I have a question about the usage of fsockopen() to open and "scrape" the contents of a remote URL: if the contents take a very long time to load on the remote URL either due to server or coding issues, is there a way for the socket on the PHP end to time out, that is, quit trying to "scrape" contents from the remote site and post a default message instead?


Yes, it is the last parameter of the fsockopen() function. Normally, it
will be set to something like 30 seconds, you might adjust it to
whatever you like. After that time you will get error 110 which means
"Connection timed out". Additionally, if you set anything over 30
seconds, you might also consider altering the execution time limit for
the php script itself.



--
Maxim Maletsky
maxim at php.net





More information about the talk mailing list