title: "Connection refused" error on socket_connect in php
body: <p>I am trying to convert some code from perl to php.</p>
  
  <p>Perl code looks like below:</p>
  
  <p><code>my $handle = Connect($port, $host);</code></p>
  
  <p>and I am trying to use socket to do the same thing in php.
  I have tried socket_create and socket_connect,
  socket_create and socket_bind, and fsocketopen.</p>
  
  <p>As a result, I'm stuck with error messages saying "Connection refused" or "permission denied":</p>
  
  <blockquote>
    <p>socket_connect() [function.socket-connect]: unable to connect [111]: Connection refused in</p>
  </blockquote>
  
  <p>I am not sure if this is the problem I need to solve, or the problem of permission because the code in perl works fine (I did not write that code).</p>
  
  <p>my php code looks like below:</p>
  
  <pre><code>$socket =  socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
  if(!$socket){
          die('Error: socket_create()');
  }
  if(!socket_connect($socket,$host,$port)) {
          die('Error: socket_connect()');
  }
  </code></pre>
  
  <p>I'm not the one who manages the server, so I will need to ask someone else for the access if it is a permission issue. What should I ask for specifically?</p>
  
  <p>Or should I use some other function to connect to the server? I am new to perl, so I am not sure if socket_connect is the equivalent function to use or not.</p>
  
  <p>Thanks.</p>