title: PHP socket error Permission denied on Linux
body: <p>I have installed php 5.4.13 on Linux 2.6.34.</p>
  
  <p>I have make simple client/server page using socket but it did not work on it.</p>
  
  <p>It give permission denied error </p>
  
  <p>Below is my php code</p>
  
  <pre><code>if (false == ($socket = socket_create(AF_INET, SOCK_STREAM, 0)))  // create socket 
  {
     $stringData= date("D M d, Y g:i A"). " socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "&lt;br&gt;";
     echo $stringData;
  }
  else
  {
      $timeout = array('sec'=&gt;5,'usec'=&gt;500000);
      socket_set_option($socket,SOL_SOCKET,SO_RCVTIMEO,$timeout);
  
      if(false==($result = socket_connect($socket, $host, $port)))
      {
          $stringData= date("D M d, Y g:i A"). " socket_connect() failed: reason: " . socket_strerror(socket_last_error()) . "&lt;br&gt;";
          echo $stringData;
          socket_close($socket);
      }
      else
      {
          $stringData= date("D M d, Y g:i A"). " Socket connected succefully &lt;br&gt;";
          echo $stringData;
  
          if(false==(socket_write($socket, $command, strlen($command))))
          {
              $stringData= date("D M d, Y g:i A"). " socket_write() failed: reason: " . socket_strerror(socket_last_error()) . "&lt;br&gt;";
              echo $stringData;
              socket_close($socket);
          }
          else
          {
              if(false===($cmd = socket_read ($socket, 65536)))
              {
                  //10060 for windows and 11 for linux
  
                if(10060!=socket_last_error() &amp;&amp; 11!=socket_last_error())
                {
                  $stringData= date("D M d, Y g:i A"). " socket_read() failed: reason: " . socket_strerror(socket_last_error()) . "&lt;br&gt;";
                  echo $stringData;
                  socket_close($socket);
  
                }
                switch(socket_select($r = array($socket), $w = array($socket), $f = array($socket), 5))
                {
                         case 2:
                                 $refused=1;  
                                 break;
                }
                if($refused==1)
                {
                  $stringData= date("D M d, Y g:i A"). " socket_read() failed: reason: Connection Refused &lt;br&gt;";
                  $ourFileHandle = fopen(SOCKET_LOG, 'a');
                  echo $stringData;
                  socket_close($socket);
  
                }
              }
              else
              {
                  echo "&lt;pre&gt;".html_entity_decode(print_r($cmd,true))."&lt;/pre&gt;";
              }
          }
      }
  }
  </code></pre>
  
  <p>Above code work fine on command prompt but it gives error Permission denied when page open from any browser.</p>
  
  <p>Command of run php from terminal : <code>/usr/local/rootfs/php5/bin/php /www/socket_client.php</code></p>