title: Php Sockets vs Streams
body: <p>I think php sockets and php streams are overlapping each other.<br>
  I've managed to make a  CLI PHP chat client and a server, using either sockets or  streams.</p>
  
  <p>Here some illustrating code lines:<br>
  Using sockets:</p>
  
  <pre><code>...
  $main_socket = @socket_create(AF_INET, SOCK_STREAM, SOL_TCP) or die("Cannot create socket.\n");
  @socket_bind($main_socket, $host, $port) or die("Could not bind to socket $host : $port.\n");
  @socket_listen($main_socket, 5) or die("Could not set up socket listener\n");
  ...
  </code></pre>
  
  <p>Using streams:</p>
  
  <pre><code>...
  $main_socket = @stream_socket_server ("tcp://$host:$port", $errno, $errstr, STREAM_SERVER_BIND | STREAM_SERVER_LISTEN) or die("Cannot create socket.\n");
  $clients = array($main_socket);
  $clients_peername = array(array('port' =&gt; $port));
  
  fputs(STDOUT, "Waiting for connections...\n");
  ...
  </code></pre>
  
  <p>The point here is that a client and a server could be made
  using either sockets functions, either streams functions.</p>
  
  <p>I know that Streams is part of PHP core and Sockets is an extension.</p>
  
  <p>My question(s) is(are):</p>
  
  <ul>
  <li>What is the difference between sockets and streams when referring to sockets programming?</li>
  <li>Are there any capabilities, related to sockets programming, that one can have while the other one cannot?</li>
  </ul>