title: How can PHP gracefully shut down a local socket connection...?
body: <p>I have a PHP client connecting to a local C server programme via a text-only Unix-domain socket. However, the only way I can get it to shutdown nicely is if I finish the socket session with:</p>
  
  <pre><code>stream_socket_shutdown($sock, 1); // shutdown socket writing
  usleep(500 * 1000);           // wait for 0.5 seconds
  fclose($sock);                // actually close the socket (finally)
  </code></pre>
  
  <p>I'd like to shut it down gracefully like my C client:-</p>
  
  <pre><code>shutdown(connection_fd, SHUT_WR);     // tell server we've stopped sending queries
  // Read from the socket until poll(connection_fd) yields POLLRDHUP / POLLHUP / POLLERR / POLLNVAL
  shutdown(connection_fd, SHUT_RDWR);   // tell connection we've stopped listening
  close(connection_fd);                 // close the whole connection (finally)
  </code></pre>
  
  <p>However, PHP doesn't appear to have a direct socket poll() equivalent. How can I get PHP to shut down my local socket gracefully?</p>