views:

64

answers:

2
$sock = fsockopen($url_parts['host'], (isset($url_parts['port']) ? (int)$url_parts['port'] : 80), $errno, $errstr, 30);
if (!$sock) return false;

I have list on my db for urls, that I am visiting, and occassionally I get this:

I am getting "Fatal error: Maximum execution time of 30 seconds exceeded..."

Its expected, since it goes to the site, that does not allow sockets or something else.

How do I skip these bad sites, so my script would continue running for other good ones?

Thanks

+1  A: 

Lower the connection timeout for fsockopen() (the last parameter of your call), which currently is set to 30 seconds. Otherwise PHP will wait for 30 seconds to connect to the remote host and then fail due to the maximum execution time.

You may play with the value to fit your needs, but usually you can assume that no connection is possible if the socket is not open within a few seconds.

Furthermore, you may want to use set_time_limit() to increase the maximum execution time of your script.

Ferdinand Beyer
+1 You said this much more elegantly than I
Mike B
I tried lowering this before, and it still gave me error, but now when I tested it again, it worked just like I wanted it. Thx
Ossi
A: 

The problem is not with the fsocketopen timing out, but with the php script reaching the max execution time set in the php.ini by default it is set at 30 seconds, if you are running php as an apache module please check the max execution time in the php.ini , increase that to get more execution time, you will notice that the option is disable on the php.ini for cli by default.

Ronald Conco