霜天部落 | 关注LAMP高性能、高并发架构的设计与研究

fsockopen(): unable to connect (Connection timed out)

Message:

PHP Warning:fsockopen(): unable to connect to stmp.exmail.qq.com:25 (Connection timed out) in /home/public_html/smtp.php on line 66

Error type: warning

Symptoms:

You try to open a socket to a remote location, but your connection is timed out (you don’t receive any response).

Sample Code:

fsockopen($ping_host, $ping_port, $errno, $errstr);

if (is_resource($fs))
{
stream_set_write_buffer($fs,0);
fwrite($fs, $http_request);
while (!feof($fs))
{
$response .= fgets($fs, 2048);
}
fclose($fs);
}
?>

Cause:


The host you are trying to connect to is either down or takes too long to respond (or from other reasons, you just can’t get a response).

Fix:

Get a beer, watch a movie, play a game … really, there’s not much you can do usually. Wait a few minutes and try again. If you still get the same response check if there is any problem with your server (for example DNS problems), eventually contact your hosting provider.