Skip to content

Commit cd69219

Browse files
author
Tianfang Yang
committed
Merge branch 'PHP-7.2'
* PHP-7.2: Update NEWS Fixed bug #74631 (PDO_PCO with PHP-FPM: OCI environment initialized before PHP-FPM sets it up)
2 parents 1287c20 + d128fdc commit cd69219

File tree

1 file changed

+46
-5
lines changed

1 file changed

+46
-5
lines changed

ext/pdo_oci/pdo_oci.c

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
#include "pdo/php_pdo_driver.h"
3030
#include "php_pdo_oci.h"
3131
#include "php_pdo_oci_int.h"
32+
#ifdef ZTS
33+
#include <TSRM/TSRM.h>
34+
#endif
3235

3336
/* {{{ pdo_oci_functions[] */
3437
const zend_function_entry pdo_oci_functions[] = {
@@ -50,7 +53,7 @@ zend_module_entry pdo_oci_module_entry = {
5053
pdo_oci_functions,
5154
PHP_MINIT(pdo_oci),
5255
PHP_MSHUTDOWN(pdo_oci),
53-
NULL,
56+
PHP_RINIT(pdo_oci),
5457
NULL,
5558
PHP_MINFO(pdo_oci),
5659
PHP_PDO_OCI_VERSION,
@@ -80,18 +83,48 @@ const ub4 PDO_OCI_INIT_MODE =
8083
/* true global environment */
8184
OCIEnv *pdo_oci_Env = NULL;
8285

86+
#ifdef ZTS
87+
/* lock for pdo_oci_Env initialization */
88+
static MUTEX_T pdo_oci_env_mutex;
89+
#endif
90+
8391
/* {{{ PHP_MINIT_FUNCTION
8492
*/
8593
PHP_MINIT_FUNCTION(pdo_oci)
8694
{
8795
php_pdo_register_driver(&pdo_oci_driver);
8896

97+
// Defer OCI init to PHP_RINIT_FUNCTION because with php-fpm,
98+
// NLS_LANG is not yet available here.
99+
100+
#ifdef ZTS
101+
pdo_oci_env_mutex = tsrm_mutex_alloc();
102+
#endif
103+
104+
return SUCCESS;
105+
}
106+
/* }}} */
107+
108+
/* {{{ PHP_RINIT_FUNCTION
109+
*/
110+
PHP_RINIT_FUNCTION(pdo_oci)
111+
{
112+
if (!pdo_oci_Env) {
113+
#ifdef ZTS
114+
tsrm_mutex_lock(pdo_oci_env_mutex);
115+
if (!pdo_oci_Env) { // double-checked locking idiom
116+
#endif
89117
#if HAVE_OCIENVCREATE
90-
OCIEnvCreate(&pdo_oci_Env, PDO_OCI_INIT_MODE, NULL, NULL, NULL, NULL, 0, NULL);
118+
OCIEnvCreate(&pdo_oci_Env, PDO_OCI_INIT_MODE, NULL, NULL, NULL, NULL, 0, NULL);
91119
#else
92-
OCIInitialize(PDO_OCI_INIT_MODE, NULL, NULL, NULL, NULL);
93-
OCIEnvInit(&pdo_oci_Env, OCI_DEFAULT, 0, NULL);
120+
OCIInitialize(PDO_OCI_INIT_MODE, NULL, NULL, NULL, NULL);
121+
OCIEnvInit(&pdo_oci_Env, OCI_DEFAULT, 0, NULL);
122+
#endif
123+
#ifdef ZTS
124+
}
125+
tsrm_mutex_unlock(pdo_oci_env_mutex);
94126
#endif
127+
}
95128

96129
return SUCCESS;
97130
}
@@ -102,7 +135,15 @@ PHP_MINIT_FUNCTION(pdo_oci)
102135
PHP_MSHUTDOWN_FUNCTION(pdo_oci)
103136
{
104137
php_pdo_unregister_driver(&pdo_oci_driver);
105-
OCIHandleFree((dvoid*)pdo_oci_Env, OCI_HTYPE_ENV);
138+
139+
if (pdo_oci_Env) {
140+
OCIHandleFree((dvoid*)pdo_oci_Env, OCI_HTYPE_ENV);
141+
}
142+
143+
#ifdef ZTS
144+
tsrm_mutex_free(pdo_oci_env_mutex);
145+
#endif
146+
106147
return SUCCESS;
107148
}
108149
/* }}} */

0 commit comments

Comments
 (0)