当前位置: 动力学知识库 > 问答 > 编程问答 >

sockets - Unable to connect with fsockopen in PHP (Connection timed out)

问题描述:

I developped an application for a friend and he recently changed his dedicated server for overload problems.

Since this migration, a part of the site doesn't work anymore : a connection on a socket in PHP.

In this part, I had to etablish a connection with an other server so I realized a function to open a socket :

function openSocket($host, $port) {

$fp = fsockopen($host, $port, $errno, $errstr, 30);

if (!$fp) {

return 0;

}

fputs($fp, $envoi);

return $fp;

}

In the code, I use this function like that :

$sock = openSocket($host, $port);

while (!feof($sock)) {

echo fread($sock, 8192);

}

fclose($sock);

Sometimes, I need to open the socket for several minutes and since the migration, my friend has this error in his log :

PHP Warning: fsockopen(): unable to connect to ...:80 (Connection

timed out) in ..., referer: ...

I searched if there was a specific configuration in PHP / Apache but I found nothing.

I tried to increase the last parameters of fsockopen or the stream_set_timeout() function but nothing worked.

Thank you for your help

网友答案:

Is there a reliable connection between the two computers?

网友答案:

Some hosting providers and dedicated server setups limit allowed outgoing connections in their firewall settings. This is especially useful to prevent unusual bot or exploit scripts from establishing connections FROM the server should it be compromised. Check if there are any egress/outgoing firewall rules that might be blocking you.

Other reasons - an ingress/inbound firewall rule on the remote server is denying your connection attempt, or highly latent connectivity between the machines.

网友答案:

Even i was facing same problem.
I was developing a site for my client.
He wanted me to set the time from the dedicated time servers.
So, i tried to establish a connection to that server using UDP. Tried a lot but failed. Long after that i found that some port was closed which was required to be open for establishing connection.
Checkout the port required and then confirm that the respective port is opened

分享给朋友:
您可能感兴趣的文章:
随机阅读: