tags:

views:

208

answers:

1

Usually closing a connection is simply done by oci_close($connection); or in a worse case when the php script ends the connection pass away.

In my case however, I face a different behavior.

If I access my application which uses PHP 5.2.8, Apache 2.2.11 and oci8 1.2.5, the connection is kept during several minutes.

Actually it seems to: if I launch netstat -b I see that the process httpd.exe remains with the ESTABLISHED status on the database's URL during a while (a few minutes).

Could someone enlighten me on that behavior?

P.S. I do not use persistent connections.

P.P.S. As asked here is the code used to connect and close (this is a legacy application):

connection: a function is called whose connection related code is $connection = @ocilogon ( "$username", "$password", "$database" );

closing: responsability of every pages we develop but typically it'd be oci_close($connection)

A: 

From the docs on oci_connect() here (ocilogon() calls the same function):

http://www.php.net/manual/en/oci8.connection.php

It implies that you can close a connection explicitly via oci_close() or that it is closed automatically at the end of the page being rendered. I would imagine if you aren't closing explicitly that it might take it some time to timeout. Is it possible, that some of the pages that don't have oci_close() calls are causing the open connections you see?

If you create a standalone page with only an oci_connect() and an oci_close() and then execute it multiple times, do you see the connection count rise directly with how many times you executed the page and stay up before eventually coming back down?

Also, what indicator are you looking at to see that the connection is remaining open?

if you were on higher versions, then it might be Oracle 11g Database Resident Connection Pooling but that doesn't exist on your current versions you are using.

Dougman
> what indicator are you looking at to see that the connection is remaining open?I use netstat from the terminal to see that a connection between my apache process (httpd.exe) keeps a connection to the database URLRegarding the eventual timeout, do you know how can I set it?
Valentin Jacquemin
@Valentin Jacquemin: That is really just showing you at the network level. You would need to query the database directly to see if it is truly an open connection in the database sense. Those are the types of connections you should be worrying about. You would query the `v$session` tables to show these connections.
Dougman
Yes I expected this suggestion, unfortunately I do not have view rights on the v$session tables.
Valentin Jacquemin
@Valentin Jacquemin: You really would need to be able to get this information to know what is going on. You will probably find that you actually aren't holding Oracle connections open. I guess you could take the opposite approach, and write a script to keep refreshing your page seeing if you can blow out the maximum number of connections. If that never happens, then you aren't holding Oracle connections open.
Dougman
@Dougman Actually it happened :) I got an oracle error saying that the max number of process has been reached. This is the why of my question.
Valentin Jacquemin
If that is the case, then sounds like your OCI driver is having issues (bugs, configuration issue). A connection followed by a close() command should destroy a connection. What kind of database work are you doing on this page? Can you post the actual code where you are creating the connection, executing the sql and closing the connection?
Dougman
I will investigate further and try to gain access to v$session tables. At least as I understand I'm not missing a key point about php/oracle interaction. Thanks for your hints @Dougman, I accept your answer.
Valentin Jacquemin