Re: can't get fsockopen() to work through IIS
| From: | Evan Burkitt | Date: | Fri, 17 Oct 2008 23:07:26 +0000 |
| Subject: | Re: can't get fsockopen() to work through IIS | ||
| References: | 1 2 | Groups: | php.windows |
| Request: | Send a blank email to php-windows+get-29047@lists.php.net to get a copy of this message | ||
"Elizabeth M Smith" <auroraeosrose@gmail.com> wrote in message
news:7B.96.19022.99709F84@pb1.pair.com...
> Take out the @ in front of fsockopen and see what the actual error is
> would be the first step - it's generally a good idea to have E_ALL on
> and all @ operators removed when trying to debug something
>
Thanks for your reply, Elizabeth. I cobbled my script up from bits of the
3rd-party application I'm trying to get running. I know little enough about
PHP that I didn't notice the '@', nor did I know its significance. My
updated script is below. PHP now reports the following:
Warning: fsockopen() [function.fsockopen]: unable to connect to
localhost:110 (Unknown error) in C:\Inetpub\wwwroot\socket_test.php on line
12
errno is still 0. "Unknown error" sounds straight from Windows'
carefully-crafted assortment of information-free error messages. :)
From http://us2.php.net/manual/en/function.fsockopen.php:
"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." Keep in mind that the fsockopen()
call succeeds when run from the command line. My suspicion is that IIS is
preventing PHP from opening the socket, but I can't find anything on the Web
discussing this either in terms of IIS alone or it in conjuction with PHP.
<?php
$host = "localhost";
$port = "110";
error_reporting(E_ALL);
?>
<html>
<h1>Attempting to open socket on host '<?php echo ("$host")?>' at
port
'<?php echo ("$port")?>'</h1>
<h2>
<?php
$errno = 0;
$errstr = "<no error reported>";
$fp = fsockopen($host, $port, $errno, $errstr);
if ($fp) {
echo "Socket connection established";
fclose($fp);
}
else {
echo "Could not connect to $host at port $port (\$errno=$errno;
\$errstr=$errstr)";
}
?>
</h2>
</html>