开发者

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, 6开发者_C百科667, $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.


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");
}

?


I fixed it.

function irCmd didn't know $socket, so I put this in front of it:

global $socket;

And it worked. Thanks a bunch!


The documentation says (emphasis mine):

If the value returned in errno is 0 and the function returned FALSE, it is an indication that the error occurred before the connect() call. This is most likely due to a problem initializing the socket.

Since the function did not return false, the socket is valid. If you are having further problems, tells us what they are; fsockopen has returned normally here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜