can"t get fsockopen() to work through IIS
can"t get fsockopen() to work through IIS
am 17.10.2008 22:17:26 von Evan Burkitt
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:
$host = "localhost";
$port = "110";
?>
Attempting to open socket on host '' at port
''
$errno = 0;
$errstr = "";
$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)";
}
?>
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.
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: can"t get fsockopen() to work through IIS
am 17.10.2008 23:46:32 von Elizabeth M Smith
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:
>
> $host = "localhost";
> $port = "110";
> ?>
>
>
Attempting to open socket on host '' at port
> ''
>
>
> $errno = 0;
> $errstr = "";
> $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)";
> }
> ?>
>
>
>
> 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
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: can"t get fsockopen() to work through IIS
am 18.10.2008 01:07:26 von Evan Burkitt
"Elizabeth M Smith" 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.
$host = "localhost";
$port = "110";
error_reporting(E_ALL);
?>
Attempting to open socket on host '' at port
''
$errno = 0;
$errstr = "";
$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)";
}
?>
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
RE: Re: can"t get fsockopen() to work through IIS
am 18.10.2008 05:42:08 von Andi Gutmans
This is almost surely a permissions problem. By default IIS will run as
a very low privileged user. I suggest in the IIS configuration you try
and run the vhost as your login user on the Windows machine and see what
happens.
Make sure your php.ini has fcgi.impersonate=3D1
Andi
> -----Original Message-----
> From: Evan Burkitt [mailto:evanb@edulinksys.com]
> Sent: Friday, October 17, 2008 4:07 PM
> To: php-windows@lists.php.net
> Subject: [PHP-WIN] Re: can't get fsockopen() to work through IIS
>=20
> "Elizabeth M Smith" 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
> >
>=20
> 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:
>=20
> Warning: fsockopen() [function.fsockopen]: unable to connect to
> localhost:110 (Unknown error) in C:\Inetpub\wwwroot\socket_test.php on
line
> 12
>=20
> errno is still 0. "Unknown error" sounds straight from Windows'
> carefully-crafted assortment of information-free error messages. :)
>=20
> 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.
>=20
>
> $host =3D "localhost";
> $port =3D "110";
> error_reporting(E_ALL);
> ?>
>
> Attempting to open socket on host '' at port
> ''
>
>
> $errno =3D 0;
> $errstr =3D "";
> $fp =3D fsockopen($host, $port, $errno, $errstr);
> if ($fp) {
> echo "Socket connection established";
> fclose($fp);
> }
> else {
> echo "Could not connect to $host at port $port (\$errno=3D$errno;
> \$errstr=3D$errstr)";
> }
> ?>
>
>
>=20
>=20
>=20
>=20
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re: can"t get fsockopen() to work through IIS
am 23.10.2008 04:52:11 von Evan Burkitt
Andi Gutmans wrote:
> This is almost surely a permissions problem. By default IIS will run as
> a very low privileged user. I suggest in the IIS configuration you try
> and run the vhost as your login user on the Windows machine and see what
> happens.
I can't figure out "vhost" is, but I tried running the IIS itself as an
administrator-level user but it won't start ("access denied" error). I
also tried putting the IIS user in the administrator's group, but
connections still didn't work.
I've given up on IIS and have installed lighttpd. That means I use PHP
CGI until I take the time to set up fastCGI, but at least I can move on
to my next issue.
Thanks for your help.
-eb-
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
RE: Re: can"t get fsockopen() to work through IIS
am 23.10.2008 06:06:12 von Andi Gutmans
OK but how about trying your login user?
Andi
> -----Original Message-----
> From: Evan Burkitt [mailto:evanb@edulinksys.com]
> Sent: Wednesday, October 22, 2008 7:52 PM
> Cc: php-windows@lists.php.net
> Subject: Re: [PHP-WIN] Re: can't get fsockopen() to work through IIS
>=20
> Andi Gutmans wrote:
> > This is almost surely a permissions problem. By default IIS will run
as
> > a very low privileged user. I suggest in the IIS configuration you
try
> > and run the vhost as your login user on the Windows machine and see
what
> > happens.
>=20
> I can't figure out "vhost" is, but I tried running the IIS itself as
an
> administrator-level user but it won't start ("access denied" error). I
> also tried putting the IIS user in the administrator's group, but
> connections still didn't work.
>=20
> I've given up on IIS and have installed lighttpd. That means I use PHP
> CGI until I take the time to set up fastCGI, but at least I can move
on
> to my next issue.
>=20
> Thanks for your help.
>=20
> -eb-
>=20
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: RE: Re: can"t get fsockopen() to work through IIS
am 23.10.2008 08:56:52 von harlequin2
Hi Evan,
there are three more things that you could check if you want to give IIS a second try:
1.) how long does the script need to output the error? Could it be that the value for "default_socket_timeout" in php.ini is very low and the call to fsockopen() fails because the server doesn't respond in time?
2.) In some cases, variable types can cause issues like yours. Although you don't define the type of variable in PHP, variable types are defined implicitly through assigning a value. In your case, your $port variable is defined as String whereas an integer is expected in the call to fsockopen(). In most cases the type will automatically be changed, but I had some problems connecting to a db2 database because the port number had been defined as a String.
3.) Try this
[CODE]
$fp = fsockopen("tcp://127.0.0.1", 110, $errno, $errstr, 30);
[/CODE]
instead of
[CODE]
$fp = fsockopen($host, $port, $errno, $errstr);
[/CODE]
What's the result of the call?
Hope to hear from you soon!
Regards, Sascha
P.S. It's good to see one of the PHP founders on the support list :)
--
GMX Kostenlose Spiele: Einfach online spielen und Spaß haben mit Pastry Passion!
http://games.entertainment.gmx.net/de/entertainment/games/fr ee/puzzle/6169196
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re: can"t get fsockopen() to work through IIS
am 23.10.2008 22:38:28 von Evan Burkitt
Andi Gutmans wrote:
> OK but how about trying your login user?
Ah. I finally figured out what you meant in your original reply: The
user and password used for anonymous access to the Web site. I entered
my own user name and password as the anonymous login in the Directory
Security / Authentication and access control dialog in my Web site's
properties page and my test script successfully opens the socket.
Now I just need to figure out what permission(s) to give to IUSR so that
it can do the same. Or just stick with lighttpd, since it works running,
presumably, as the SYSTEM user.
Sascha Meyer's post alerted me to who you are. I admit that knowing I
was corresponding with one of the PHP icons pushed me to have another
look at this. I'm glad I did, as I learned something new, but I sure
wish I could get back even half the hours I've spent on this project so
far. :)
Thanks for your help.
-evan
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re: can"t get fsockopen() to work through IIS
am 23.10.2008 22:38:35 von Evan Burkitt
Sascha Meyer wrote:
>
> there are three more things that you could check if you want to give IIS a second try:
See my reply to Andi's post. Since the script works from the command
line I had to assume that the problem wasn't with PHP itself, but rather
the fact that it was being executed as IUSR by IIS. Since I have now
determined that to be so I have at least an idea of where to go next.
Thanks for your help.
-evan
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php