tags:

views:

20

answers:

3

When I call to a page through ajax should I close the connection at the end ?

The ajaxed file has a connection string for itself ofcourse, so I wonder if this connection stays open when the call is over, and if it's a disaster to not close these connections...

Thanks in advance to all

+1  A: 

PHP will close all open files and DB connections at the end of the script. it's good practice to do it manually when you are done with the connections, but it's no disaster if you don't.

Emil Vikström
+3  A: 

When you call a PHP page through AJAX you are actually making a new request to the server to interpret that page. The server does not know anything about the page being requested through AJAX or by typing the address in the browser bar, it just interprets it as a new PHP page.

That said, all pending connections are closed automatically, you can put mysql_close if you wish, otherwise PHP will do it for you.

See the manual page for mysql_close

Using mysql_close() isn't usually necessary, as non-persistent open links are automatically closed at the end of the script's execution.

nico
A: 

Thanks all. Now I understand it's not a must.

OfficeJet