[PHP] Intermittent etwork connection errors with apache. Restarting apache temporarily fixes the problem. PHP or apache problem?

2010-01-04 Thread Mark London
Hi - At the top of my php scripts, I have code to connect to our ldap 
server, in order for the scripts to make ldap requests.  I don't have 
any disconnect call in my code.  Lately I have noticed that the apache 
server will get into a state where connection requests will occasionally 
fail.  When I refresh the page, the connection almost always succeeds on 
the 2nd attempt.   If I restart the apache server, the problem totally 
goes away for a long period of time.   So I assume that somewhere, 
something is causing connections to stay opened when the script ends, 
rather than automatically closing them.


This error occurs with other types of network connections that the 
script makes (besides ldap), so it's not an ldap issue.


How does Apache automatically close connections when the script ends?  
Is it possible that connections are being left opened?  Is there any way 
to debug the problem, i.e. to see if connections are left opened in some 
way?


I'm running redhat 5, httpd-2.2.3-31.el5_4.2 php-5.1.6-23.2.el5_3

Thanks. - Mark

  


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Intermittent etwork connection errors with apache. Restarting apache temporarily fixes the problem. PHP or apache problem?

2010-01-04 Thread Andy Shellam
Hi Mark,


 I don't have any disconnect call in my code.  

Is this the same for all your connections code, apart from your LDAP?  It's 
good practice to never assume that PHP will disconnect connections for you - 
explicitly call the disconnect function when your connection is done with.

 Lately I have noticed that the apache server will get into a state where 
 connection requests will occasionally fail.  When I refresh the page, the 
 connection almost always succeeds on the 2nd attempt.   If I restart the 
 apache server, the problem totally goes away for a long period of time.   

Are you talking about the connection to Apache or the connection from your 
Apache server to your other servers?

 So I assume that somewhere, something is causing connections to stay opened 
 when the script ends, rather than automatically closing them.

As I said above, always explicitly disconnect from any services you connect to 
when you're finished.

 
 This error occurs with other types of network connections that the script 
 makes (besides ldap), so it's not an ldap issue.
 
 How does Apache automatically close connections when the script ends?  Is it 
 possible that connections are being left opened?  Is there any way to debug 
 the problem, i.e. to see if connections are left opened in some way?

Run netstat -an|grep tcp on the server's console before and after a page 
request - if possible prevent all other connections to your Apache server while 
you do it.

Connections that remain open will be in the state ESTABLISHED - server 
processes (e.g. Apache) will be listed as LISTEN.

If you get an LDAP connection after your page request that wasn't there before 
in the ESTABLISHED state, PHP isn't disconnecting.

If any connections are listed as TIME_WAIT, it means the connection was dropped 
without the client disconnecting properly - it may be worth running netstat on 
your LDAP server as well.

Regards,
Andy
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php