|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2007-10-23 22:08 UTC] david at acz dot org
[2007-10-23 23:41 UTC] david at acz dot org
[2007-11-12 10:21 UTC] tony2001@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 19:00:01 2025 UTC |
Description: ------------ OCI8 persistent connections cannot, by design, be closed. The consequence is that if the connection fails then the only recourse is to restart PHP. oci_pconnect always returns the same dead connection. The PHP application itself cannot correct the issue. Connections can fail due to idle timeouts, session kills, etc. Two suggested fixes: 1) Add an oci_pclose() that always closes persistent connections. 2) Close or allow the connection to be closed after certain errors such as 28, 1012, 2396, 3114, etc. There are at least two ways to run the test and reproduce the error: 1) After you see the "sleeping" line, kill the session with ALTER SYSTEM KILL SESSION. 2) Increase the sleep to 300 seconds and lower the idle timeout in the database to 1 minute. The code was tested with OCI 1.3.0 Beta (Revision: 1.269.2.16.2.38.4.1). Reproduce code: --------------- <? $o = oci_pconnect(DB_USER, DB_PASS, DB_NAME); var_dump($o); if ($o === false) { $err = oci_error(); print_r($err); } $sql = "ALTER SESSION SET NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS'"; query($o, $sql); echo "sleeping\n"; sleep(60); if (!query($o, $sql)) { echo "query failed, closing connection\n"; var_dump(oci_close($o)); $o = oci_pconnect(DB_USER, DB_PASS, DB_NAME); var_dump($o); if ($o === false) { $err = oci_error(); print_r($err); } echo "reconnected\n"; var_dump(query($o, $sql)); } function query($o, $sql) { $s = @oci_parse($o, $sql); if ($s === false) { $err = oci_error($o); print_r($err); return false; } if (!@oci_execute($s, OCI_COMMIT_ON_SUCCESS)) { $err = oci_error($s); print_r($err); return false; } oci_free_statement($s); return true; } ?> Actual result: -------------- resource(4) of type (oci8 persistent connection) sleeping Array ( [code] => 28 [message] => ORA-00028: your session has been killed [offset] => 0 [sqltext] => ALTER SESSION SET NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS' ) query failed, closing connection bool(true) resource(8) of type (oci8 persistent connection) reconnected Array ( [code] => 1012 [message] => ORA-01012: not logged on [offset] => 0 [sqltext] => ALTER SESSION SET NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS' ) bool(false)