From: <php...@li...> - 2010-06-17 00:23:54
|
Hi, How would you persist an open JDBC connection across invocations of the same PHP script but at different times, from different computers? For example the following does not work: // Load the PostgreSQL database driver. // java( 'java.lang.Class' )->forName( 'org.postgresql.Driver' ); $conn = apc_fetch( $PERSIST ); if( $conn === false || $conn->isClosed() ) { echo "Reloading JDBC connection: $conn\n"; exit; // Attempt a database connection. // $conn = java( 'java.sql.DriverManager' )->getConnection( "jdbc:postgresql://$dbhost/$dbname?user=$dbuser&password=$dbpass" ); // Failure to add is fine; it means the above fetch will fail, and // thus recreate the JDBC connection each time. Not ideal; might have // a performance impact. // apc_delete( $PERSIST ); apc_store( $PERSIST, $conn ); } The $conn is always closed after the script ends. The only other way I can think of to prevent this from happening is to implement my own PostgreSQL Connection subclass, and override "close()" to do nothing. The problem I'm trying to solve is that the PG database reloads PL/R modules for each new database connection. What I need is some sort of persistent JDBC connection pool for the PHP-Java bridge. Any ideas? Thank you! Dave |