开发者

fsockopen error I want to skip

$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开发者_Go百科 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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜