At the end of each script, connections opened with oci_connect() or oci_new_connect()
are automatically closed. You can also explicitly close them at any time by calling: oci_close($c);
Any uncommitted data is rolled back.
If a long running script only spends a small amount of time interacting with the database,
you may want to close connections to free resources for other users.
Connections opened with oci_pconnect() will not be closed by oci_close(). This is
similar to the way persistent resources work in other PHP extensions. Idle persistent
connections can be set to expire.
The oci_close() function was a “no-op” prior to the re-factoring of OCI8. That is, it
had no functional code, and never actually closed a connection. You could not explicitly
close connections even if you wanted to! This has now changed, but you can revert to the old
behavior if necessary with this php.ini setting: oci8.old_oci_close_semantics = 1
oci_close() works by reference counting. Only when all references to the PHP connection
are finished will the database connection actually be closed. In this example $c1 and $c2 are
the one database connection (because oci_connect() returns the same connection resource
when called more than once in a script), but only at the end of script when $c2 is closed is the
database connection really released.
<?php
function do_query($c, $query)
{
$s = oci_parse($c, $query);
oci_execute($s);
oci_fetch_all($s, $res);
echo "<pre>";
var_dump($res);
echo "</pre>";
}
$c1 = oci_connect('hr', 'hrpwd', '//localhost/XE');
$c2 = oci_connect('hr', 'hrpwd', '//localhost/XE');
do_query($c1, 'select user from dual');
oci_close($c1);
do_query($c1, 'select user from dual'); // fails
do_query($c2, 'select user from dual'); // succeeds
oci_close($c2);
?>