From 079bc324cd68532334a8c227d4aacb061f8bfe8c Mon Sep 17 00:00:00 2001 From: Ingmar Runge Date: Mon, 22 May 2017 16:21:59 +0200 Subject: [PATCH 1/2] Fixed bug #74631 (PDO_PCO with PHP-FPM: OCI environment initialized before PHP-FPM sets it up) --- NEWS | 4 ++++ ext/pdo_oci/pdo_oci.c | 51 ++++++++++++++++++++++++++++++++++++++----- 2 files changed, 50 insertions(+), 5 deletions(-) diff --git a/NEWS b/NEWS index ee4ffab2ef9c6..f0cdd2b8b12f7 100644 --- a/NEWS +++ b/NEWS @@ -8,6 +8,10 @@ PHP NEWS - CURL: . Fixed bug #75093 (OpenSSL support not detected). (Remi) +- PDO_OCI: + . Fixed bug #74631 (PDO_PCO with PHP-FPM: OCI environment initialized + before PHP-FPM sets it up). (Ingmar Runge) + - Standard: . Fixed bug #75097 (gethostname fails if your host name is 64 chars long). (Andrea) diff --git a/ext/pdo_oci/pdo_oci.c b/ext/pdo_oci/pdo_oci.c index 37e930eb1c132..dfb67d758da68 100644 --- a/ext/pdo_oci/pdo_oci.c +++ b/ext/pdo_oci/pdo_oci.c @@ -29,6 +29,9 @@ #include "pdo/php_pdo_driver.h" #include "php_pdo_oci.h" #include "php_pdo_oci_int.h" +#ifdef ZTS +#include +#endif /* {{{ pdo_oci_functions[] */ const zend_function_entry pdo_oci_functions[] = { @@ -52,7 +55,7 @@ zend_module_entry pdo_oci_module_entry = { pdo_oci_functions, PHP_MINIT(pdo_oci), PHP_MSHUTDOWN(pdo_oci), - NULL, + PHP_RINIT(pdo_oci), NULL, PHP_MINFO(pdo_oci), PHP_PDO_OCI_VERSION, @@ -82,18 +85,48 @@ const ub4 PDO_OCI_INIT_MODE = /* true global environment */ OCIEnv *pdo_oci_Env = NULL; +#ifdef ZTS +/* lock for pdo_oci_Env initialization */ +static MUTEX_T pdo_oci_env_mutex; +#endif + /* {{{ PHP_MINIT_FUNCTION */ PHP_MINIT_FUNCTION(pdo_oci) { php_pdo_register_driver(&pdo_oci_driver); + // Defer OCI init to PHP_RINIT_FUNCTION because with php-fpm, + // NLS_LANG is not yet available here. + +#ifdef ZTS + pdo_oci_env_mutex = tsrm_mutex_alloc(); +#endif + + return SUCCESS; +} +/* }}} */ + +/* {{{ PHP_RINIT_FUNCTION + */ +PHP_RINIT_FUNCTION(pdo_oci) +{ + if (!pdo_oci_Env) { +#ifdef ZTS + tsrm_mutex_lock(pdo_oci_env_mutex); + if (!pdo_oci_Env) { // double-checked locking idiom +#endif #if HAVE_OCIENVCREATE - OCIEnvCreate(&pdo_oci_Env, PDO_OCI_INIT_MODE, NULL, NULL, NULL, NULL, 0, NULL); + OCIEnvCreate(&pdo_oci_Env, PDO_OCI_INIT_MODE, NULL, NULL, NULL, NULL, 0, NULL); #else - OCIInitialize(PDO_OCI_INIT_MODE, NULL, NULL, NULL, NULL); - OCIEnvInit(&pdo_oci_Env, OCI_DEFAULT, 0, NULL); + OCIInitialize(PDO_OCI_INIT_MODE, NULL, NULL, NULL, NULL); + OCIEnvInit(&pdo_oci_Env, OCI_DEFAULT, 0, NULL); +#endif +#ifdef ZTS + } + tsrm_mutex_unlock(pdo_oci_env_mutex); #endif + } return SUCCESS; } @@ -104,7 +137,15 @@ PHP_MINIT_FUNCTION(pdo_oci) PHP_MSHUTDOWN_FUNCTION(pdo_oci) { php_pdo_unregister_driver(&pdo_oci_driver); - OCIHandleFree((dvoid*)pdo_oci_Env, OCI_HTYPE_ENV); + + if (pdo_oci_Env) { + OCIHandleFree((dvoid*)pdo_oci_Env, OCI_HTYPE_ENV); + } + +#ifdef ZTS + tsrm_mutex_free(pdo_oci_env_mutex); +#endif + return SUCCESS; } /* }}} */ From 1b8a71e7401d5f6d6fb978ec33d4109d33bbd799 Mon Sep 17 00:00:00 2001 From: Tianfang Yang Date: Tue, 22 Aug 2017 01:43:07 -0400 Subject: [PATCH 2/2] Update NEWS --- NEWS | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/NEWS b/NEWS index 052e9a78cbd73..9b1e9362d053c 100644 --- a/NEWS +++ b/NEWS @@ -8,6 +8,10 @@ PHP NEWS - CURL: . Fixed bug #75093 (OpenSSL support not detected). (Remi) +- PDO_OCI: + . Fixed bug #74631 (PDO_PCO with PHP-FPM: OCI environment initialized + before PHP-FPM sets it up). (Ingmar Runge) + - Standard: . Fixed bug #75097 (gethostname fails if your host name is 64 chars long). (Andrea)