title: PHP Warning: socket_read(): unable to read from socket [104]: Connection reset by peer
body: <p>I use <code>socket_create()</code> to create socket Resource,then I bind an <code>IP</code> address to it by <code>socket_bind()</code>, its works fine; </p>
  
  <p>But after a while(more than 30 minutes) in line <code>socket_read($sock, 2048)</code> this error thrown :</p>
  
  <p><code>"PHP Warning:  socket_read(): unable to read from socket [104]: Connection reset by peer in test.php on line 198"</code>. </p>
  
  <p>This is my simplified code:</p>
  
  <pre><code>$this-&gt;sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
  
  // check if tcp socket ceated or not
  if ($this-&gt;sock === false) {
      $errorcode = socket_last_error();
      $errormsg = socket_strerror($errorcode);
       die("Couldn't create socket: [$errorcode] $errormsg");
  }
  
  // Bind the source address
  socket_bind($this-&gt;sock, $this-&gt;ip);
  // Connect to destination address
  socket_connect($this-&gt;sock, $this-&gt;mxHost, $this-&gt;port);
  $buf = socket_read($this-&gt;sock, 2048);
  </code></pre>
  
  <p>This piece of code make a SMTP(port 25) connection to a MX Host at the other side.
  Maybe it's the fault on the other side of your connection, But how can I detect that the other side isn't ready for the connection right now. In the other word how can I find out the "Connection reset by peer" occurred? </p>