Skip to content

Commit 4bf1a11

Browse files
author
Tianfang Yang
committed
Merge branch 'pull-request/2534' into PHP-7.0
* pull-request/2534: Fixed bug #74631 (PDO_PCO with PHP-FPM: OCI environment initialized before PHP-FPM sets it up)
2 parents 61538eb + 079bc32 commit 4bf1a11

File tree

2 files changed

+50
-5
lines changed

2 files changed

+50
-5
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ PHP NEWS
88
- CURL:
99
. Fixed bug #75093 (OpenSSL support not detected). (Remi)
1010

11+
- PDO_OCI:
12+
. Fixed bug #74631 (PDO_PCO with PHP-FPM: OCI environment initialized
13+
before PHP-FPM sets it up). (Ingmar Runge)
14+
1115
- Standard:
1216
. Fixed bug #75097 (gethostname fails if your host name is 64 chars long). (Andrea)
1317

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[] = {
@@ -52,7 +55,7 @@ zend_module_entry pdo_oci_module_entry = {
5255
pdo_oci_functions,
5356
PHP_MINIT(pdo_oci),
5457
PHP_MSHUTDOWN(pdo_oci),
55-
NULL,
58+
PHP_RINIT(pdo_oci),
5659
NULL,
5760
PHP_MINFO(pdo_oci),
5861
PHP_PDO_OCI_VERSION,
@@ -82,18 +85,48 @@ const ub4 PDO_OCI_INIT_MODE =
8285
/* true global environment */
8386
OCIEnv *pdo_oci_Env = NULL;
8487

88+
#ifdef ZTS
89+
/* lock for pdo_oci_Env initialization */
90+
static MUTEX_T pdo_oci_env_mutex;
91+
#endif
92+
8593
/* {{{ PHP_MINIT_FUNCTION
8694
*/
8795
PHP_MINIT_FUNCTION(pdo_oci)
8896
{
8997
php_pdo_register_driver(&pdo_oci_driver);
9098

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

98131
return SUCCESS;
99132
}
@@ -104,7 +137,15 @@ PHP_MINIT_FUNCTION(pdo_oci)
104137
PHP_MSHUTDOWN_FUNCTION(pdo_oci)
105138
{
106139
php_pdo_unregister_driver(&pdo_oci_driver);
107-
OCIHandleFree((dvoid*)pdo_oci_Env, OCI_HTYPE_ENV);
140+
141+
if (pdo_oci_Env) {
142+
OCIHandleFree((dvoid*)pdo_oci_Env, OCI_HTYPE_ENV);
143+
}
144+
145+
#ifdef ZTS
146+
tsrm_mutex_free(pdo_oci_env_mutex);
147+
#endif
148+
108149
return SUCCESS;
109150
}
110151
/* }}} */

0 commit comments

Comments
 (0)