I work with two servers which send data to each other using PHP fsockopen(). The code has been working fine for years on Windows Server 2008 R2. We recently set up a new server on Windows Server 2016. On this server, things work fine most of the time, but intermittently the socket error pops up: send of X bytes failed with errno=10054 An existing connection was forcibly closed by the remote host.
We initially thought there might be a network issue with the new server, and set up another one (also Windows Server 2016) with a different provider, only to have the same intermittent issue.
As it is intermittent, and only experienced on Windows Server 2016, I am assuming there has been some change in the newer versions of Windows Server which impacts sockets/TCP connections, but I cannot work out what! I'm not a socket expert, and any suggestions gratefully received.
FYI - the servers are fairly low traffic, and using TCPView I can see that there are usually about 100 TCP connections establisted at any one time (20ish Established, 40ish Listening, and 25ish in Time Wait). This doesn't seem like enough to me to cause issues with running out of ports/maxing out TCP connections, but I don't know enough on the topic to be sure!
This is for Windows Server 2016, running PHP 5.3 (old, I know).
$fp=fsockopen("ssl://$server1_IP", 443, $errno, $errstr, 10);
if($fp)
{
$eol="\r\n";
fputs($fp, "POST example.php HTTP/1.1$eol");
fputs($fp, "HOST: $server1_IP$eol");
fputs($fp, "Connection: close$eol");
fputs($fp, "Content-Type: application/x-www-form-urlencoded$eol");
fputs($fp, 'Content-Length: '.strlen($data).$eol);
fputs($fp, $eol);
fputs($fp, $data);
fputs($fp, $eol);
while(!feof($fp))
{
$response=fgets($fp, 4000);
}
fclose($fp);
}