php-windows Digest 17 Oct 2008 23:07:39 -0000 Issue 3529
Topics (messages 29045 through 29047):
can't get fsockopen() to work through IIS
29045 by: Evan Burkitt
29046 by: Elizabeth M Smith
29047 by: Evan Burkitt
Administrivia:
To subscribe to the digest, e-mail:
[EMAIL PROTECTED]
To unsubscribe from the digest, e-mail:
[EMAIL PROTECTED]
To post to the list, e-mail:
[EMAIL PROTECTED]
----------------------------------------------------------------------
--- Begin Message ---
I have PHP 5.2.6 installed under Windows Server 2003 and IIS 6.0. I cannot
get fsockopen() to succeed when run through IIS.
I'm using this script:
<?php
$host = "localhost";
$port = "110";
?>
<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>
When I run it through a Web browser $fp is null, $errno is 0 and $errstr is
empty. When I run it from a command line, using the IIS Internet user's
credentials, the connection succeeds and $fp is non-null.
I would appreciate any suggestions.
--- End Message ---
--- Begin Message ---
Evan Burkitt wrote:
> I have PHP 5.2.6 installed under Windows Server 2003 and IIS 6.0. I cannot
> get fsockopen() to succeed when run through IIS.
> I'm using this script:
> <?php
> $host = "localhost";
> $port = "110";
> ?>
> <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>
>
> When I run it through a Web browser $fp is null, $errno is 0 and $errstr is
> empty. When I run it from a command line, using the IIS Internet user's
> credentials, the connection succeeds and $fp is non-null.
>
> I would appreciate any suggestions.
>
>
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,
Elizabeth Smith
--- End Message ---
--- Begin Message ---
"Elizabeth M Smith" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> 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>
--- End Message ---