Search code examples
phpsocketsfsockopen

fsockopen not working?


I am trying to connect to an IRC server via PHP on a command line using Windows 7.

Everytime when running this:

$socket = fsockopen($irc_server, 6667, $errno, $errstr, 5);

$errno = 0, $errstr = "" and $socket = 'Resource id #4' (using die($socket);)

What is the cause of this, and how can I debug more into this.

The following code:

$s = fsockopen("google.com", 80, $errno, $errstr, 5);
die($errno.", ".$errstr.", ".$s);

...returns the following:

0, , Resource id #4

I can't use $socket. It says "Invalid resource" when I try to use it. Also, the PHP documentation notes that errno 0 indicates a wrongly opened socket.

Help is appreciated.


Solution

  • Could you show us a little more of your code?

    What happens with this code:

    $s = fsockopen($irc_server, 6667, $errno, $errstr, 5);
    if ($s === false) {
      die($errno.", ".$errstr.", ".$s);
    } else {
      // your code with socket
      die("Valid socket resource");
    }
    

    ?