title: Could not run socket server
body: <p>First thing, I could see out there has already solved questions around the problem. </p>
  
  <p><a href="https://stackoverflow.com/questions/13698397/php-web-socket-unable-to-bind-socket?rq=1">PHP web socket unable to bind socket</a></p>
  
  <p><a href="https://stackoverflow.com/questions/9898764/issue-in-setting-the-socket-server">Issue in setting the socket server</a></p>
  
  <p><a href="https://stackoverflow.com/questions/10720067/socket-bind-unable-to-bind-address-99-ubuntu-on-amazon-ec2?rq=1">socket_bind(): unable to bind address [99] (Ubuntu on Amazon EC2)</a></p>
  
  <p>and many other resources, all of them said that problem is in-used port or external IP, 
  etc.</p>
  
  <p>But I could not get over it.
  My server is running on CentOS 6.3 and using CPanel (it is the HP server <a href="https://www.hpcloud.com/" rel="nofollow noreferrer">https://www.hpcloud.com/</a>).</p>
  
  <p>The web socket demo source code what I get is on <a href="https://code.google.com/p/phpwebsocket/" rel="nofollow noreferrer">https://code.google.com/p/phpwebsocket/</a></p>
  
  <p>My setting is </p>
  
  <pre><code>$master  = WebSocket("127.0.0.1",4444); // even I tried with localhost, they worked same
  </code></pre>
  
  <p>Here is the step what I tried and the corresponding errors:</p>
  
  <p>1/. I tried following commands to ensure a port which I was using is available to use</p>
  
  <blockquote>
  <pre><code>$ lsof|grep 4444
  
  $ netstat -a -p -n
  </code></pre>
  </blockquote>
  
  <p>But I always got the error although this port 4444 is free </p>
  
  <blockquote>
    <p>Warning: socket_bind(): unable to bind
    address [98]: Address already in use in
    /home/myapp/public_html/websocket/server.php on line 60</p>
  </blockquote>
  
  <p>2/. The strange thing is when I checked the port 835 which was using by</p>
  
  <pre><code> crond      1621      root  DEL       REG              252,1               39835 /lib64/libpam.so.0.82.2.#prelink#.B1eyGx
  
  atd        1633      root  DEL       REG              252,1               39835 /lib64/libpam.so.0.82.2.#prelink#.B1eyGx 
  </code></pre>
  
  <p>The funny thing happened:</p>
  
  <p>Then I ran the server.php on my terminal command shell</p>
  
  <pre><code> php /home/myapp/public_html/websocket/server.php
  </code></pre>
  
  <p>the error has gone, instead of it is</p>
  
  <blockquote>
    <p>Server Started : 2013-08-16 03:19:54</p>
    
    <p>Master socket  : Resource id #4</p>
    
    <p>Listening on   : 127.0.0.1 port 835</p>
  </blockquote>
  
  <p>I thought that it started working, but actually it did not, because when I open <code>server.php</code> by the browser with URL </p>
  
  <pre><code>http://mysite/server.php
  </code></pre>
  
  <p>The error is "permission denined"</p>
  
  <blockquote>
    <p>Warning: socket_bind() [function.socket-bind]: unable to bind address
    [13]: Permission denied in
    /home/myapp/public_html/websocket/server.php on line 60
    socket_bind() failed</p>
  </blockquote>
  
  <p>Edited: About permission, I could open the client.html in same level directory with server.php without problem.
  The folder code permission is 755 and user is not root.
  All of my commands was implemented under root privilege</p>
  
  <p>Any help is greatly appreciated :( </p>