logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Other Software View previous topic :: View next topic
Reply to topic   Topic: PHP name resolution fails from Apache but ok via CLI
Author
sittingbull



Joined: 16 Aug 2006
Posts: 6
Location: techy

PostPosted: Thu 18 Sep '08 11:24    Post subject: PHP name resolution fails from Apache but ok via CLI Reply with quote

HI,

I'm using the latest Apache 2.2.9 and mod-fcgid from this site. I've installed PHP 5.2.6 from php.net.

Unfortunately any function or operation in PHP that requires a dns lookup fails. Why am I posting this here?

Using fsockopen with a host name rather than ip demonstrates nicely resulting in the error

Code:
php_network_getaddresses: getaddrinfo failed: No such host is known.


However, running the script from the command line resolves the host perfectly every time. I can use php.exe or php-cgi.exe from the command line and it works.

It's only when the php-cgi is used through apache that the problem occurs.

Various hints round the web indicate that disabling ipv6 support in php 5.2.6 might sort it but given that the php-cgi and php.exe both work when outside of apache AND I can't disable ipv6 in php without compiling from source (no thanks!) I'm hoping that this is something someone here has run into.

Thanks.
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7288
Location: Germany, Next to Hamburg

PostPosted: Sat 20 Sep '08 16:53    Post subject: Reply with quote

Hi!
Did you specified PHPinidir? Please post PHP part from your httpd.conf
Back to top
sittingbull



Joined: 16 Aug 2006
Posts: 6
Location: techy

PostPosted: Sun 21 Sep '08 11:30    Post subject: Reply with quote

Thanks.

It wasn't set because I've never had cause to in any prior installs.

phpinfo() shows that the c:\php\php.ini files is being used. GD, mysql, zip all work fine leading me to believe all the modules are found.

Adding PHPINIDir anyway stops apache from loading (perhaps because I'm not using php module, there is no PHPINIDir directive?)

The two lines pertaining to php, the only ones I've ever needed on all previous installs are:

AddHandler fcgid-script .php
FCGIWrapper "c:/php/php-cgi.exe" .php

Both of these lines are in an apache Directory directive.
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7288
Location: Germany, Next to Hamburg

PostPosted: Sun 21 Sep '08 14:06    Post subject: Reply with quote

My set up for PHP with fcgid

Code:

LoadModule fcgid_module modules/mod_fcgid.so
<IfModule mod_fcgid.c>

   IPCCommTimeout 40
   IPCConnectTimeout 10
   MaxProcessCount 8
   OutputBufferSize 64
   ProcessLifeTime 240
   MaxRequestsPerProcess 500
   SetEnv PHPRC "C:/server2/php"
   DefaultInitEnv TEMP "C:/server2/tmp"
   DefaultMinClassProcessCount 0
   
   Alias /fcgi/ "C:/server2/fcgi/"
   <Directory c:/server2/fcgi>   
      AddHandler fcgid-script .php
      Options Indexes FollowSymLinks ExecCGI
      FCGIWrapper "C:/server2/php/php-cgi.exe" .php
      AllowOverride all
      Order allow,deny
      Allow from all
      Satisfy any
   </Directory>

</IfModule>


Is php_sockets.dll loaded? But I think it is.

Can you post an example script, so that I can test your script on my fcgid?
Back to top
sittingbull



Joined: 16 Aug 2006
Posts: 6
Location: techy

PostPosted: Mon 22 Sep '08 10:31    Post subject: Reply with quote

Hi I have similar fcgi setup. I only posted the lines specific to php.

I have used your setup (with folder name changes of course) and have my test script located at /fcgi/index.php now.

The result was the same but your mention of sockets prompted me to change my test script from this

Code:
echo gethostnamebyaddr('www.google.com')


to this, in order to test socket functionality without resolver's use of sockets masking the true problem.

Code:
$f=fsockopen('127.0.0.1',80,$errno,$errstr,5);


The output of this was an error number of zero, no error string but a php warning saying

Code:
Warning: fsockopen() [function.fsockopen]: unable to connect to 127.0.0.1:80 (Unknown error)


This implies that socket functionality is NOT loaded although phpinfo() shows registered stream socket transports as tcp and udp and down in the modules section it says "sockets" and "sockets support enabled" in the table.

Despite phpinfo() it would seem that socket functionality is not available to me rather than just dns. That's a relief in some way!

Thanks for your help so far. I'm off to check for dlls with process explorer etc.
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7288
Location: Germany, Next to Hamburg

PostPosted: Mon 22 Sep '08 11:51    Post subject: Reply with quote

The first function does not exist! there is only

gethostbyaddr or gethostbyname but no gethostnamebyaddr.

But very strange! I made a simple testscript. I'm confused, Cause it works fine with the apache module, but not with fcgid where I use the same php.ini !!



Code:

<?php
$name = gethostbyname("www.google.com");
echo $name;
?>
<hr />
<?php
$f=fsockopen('www.google.com',80,$errno,$errstr,5);
?>


I tried also file() , but I always get that error "php_network_getaddresses: gethostbyname" I searching for a solution.
Back to top
sittingbull



Joined: 16 Aug 2006
Posts: 6
Location: techy

PostPosted: Mon 22 Sep '08 12:02    Post subject: Reply with quote

Sorry James, typo in my function name. I was using gethostbyname.

Well I'm certainly relieved that it's reproducible.

The same httpd.conf and php.ini worked just fine with Apache 2.2.5 (from this site) and php 5.2.4.

I will try to use php 5.2.4 with this apache install and see if I can isolate further.

I can't spend much time on this today but it's great that you are searching too! I wonder if others have the problem with 2.2.9/5.2.6 (perhaps the issue lies in fcgi?) and just don't realise because they do use sockets?

Among my searching last week I came across mention in some php source code of "sockets broken in fastcgi". May be relevant but as I said, I have sockets working just fine with fcgid and earlier apache/php.
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7288
Location: Germany, Next to Hamburg

PostPosted: Mon 22 Sep '08 14:20    Post subject: Reply with quote

It is not an error in the socket itself, but in resolve the DNS. fsockopen and file (when try to open http) use gethostbyname to resolve the hostname to an ip.

----
edit:
found something in the bug database http://bugs.php.net/bug.php?id=40234


Last edited by James Blond on Mon 22 Sep '08 14:33; edited 1 time in total
Back to top
sittingbull



Joined: 16 Aug 2006
Posts: 6
Location: techy

PostPosted: Mon 22 Sep '08 14:29    Post subject: Reply with quote

I don't think that's the case.
fsockopen is failing with unknown error even when connecting to "127.0.0.1". No name resolution required.
I tried it with a number of other ip addresses and it too failed.

This simple script
Code:

<?php
  $f=fsockopen('127.0.0.1',80,$errno,$errstr);
?>

fails with unknown error regardless of ip address when its run through apache/fcgid.

Presumably the name resolution functions resort to sockets at some point so the fact that sockets are not available would result in the name resolution error.

The same script using php.exe or php-cgi.exe works from the command line.
Back to top
sittingbull



Joined: 16 Aug 2006
Posts: 6
Location: techy

PostPosted: Thu 25 Sep '08 14:35    Post subject: Reply with quote

I haven't been able to make any progress at all with this yet. Anyone else?
Back to top
Juel



Joined: 15 Feb 2010
Posts: 3

PostPosted: Mon 15 Feb '10 19:51    Post subject: Reply with quote

Hi..
Did you solve this? Im having the exakt same problem.. Sad

Kind regards
Morten
Back to top
glsmith
Moderator


Joined: 16 Oct 2007
Posts: 2268
Location: Sun Diego, USA

PostPosted: Mon 15 Feb '10 21:46    Post subject: Reply with quote

Just thought I'd join in the fun .. even pulled out old 2.2 of mod_fcgid

PHP 5.2.12
mod_fcgid 2.2c
James's little test script and I get

gethostbyname 66.102.7.106
$f: Resource id #1
$errno: 0
$errstr:

so it can't be mod_fcgid or Apache

So this leaves me with the question, what can cause a socket to not open?

Firewall comes to mind. Specifically a firewall other than the one built into windows that monitors socket activity and what is calling on the socket (like Norton or ZoneAlarm). Not saying this is the case here.

Anti-Virus ... although it will not lock a socket it can lock a process from completing ... and if it happens to be locking the process before opening the socket it is not going to be able to open the socket at this point. Not saying this is the case here either, just thinking out loud.

James is recently familiar with AV getting in the way of mod_fcgid .. only for him it kept Apache from starting.

Edit:
Didn't notice this is a year and a half old thread that had been resurected by the previous poster.
Back to top


Reply to topic   Topic: PHP name resolution fails from Apache but ok via CLI View previous topic :: View next topic
Post new topic   Forum Index -> Other Software