pdo_oci.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. +----------------------------------------------------------------------+
  3. | Copyright (c) The PHP Group |
  4. +----------------------------------------------------------------------+
  5. | This source file is subject to version 3.01 of the PHP license, |
  6. | that is bundled with this package in the file LICENSE, and is |
  7. | available through the world-wide-web at the following url: |
  8. | https://www.php.net/license/3_01.txt |
  9. | If you did not receive a copy of the PHP license and are unable to |
  10. | obtain it through the world-wide-web, please send a note to |
  11. | license@php.net so we can mail you a copy immediately. |
  12. +----------------------------------------------------------------------+
  13. | Author: Wez Furlong <wez@php.net> |
  14. +----------------------------------------------------------------------+
  15. */
  16. #ifdef HAVE_CONFIG_H
  17. #include "config.h"
  18. #endif
  19. #include "php.h"
  20. #include "php_ini.h"
  21. #include "ext/standard/info.h"
  22. #include "pdo/php_pdo.h"
  23. #include "pdo/php_pdo_driver.h"
  24. #include "php_pdo_oci.h"
  25. #include "php_pdo_oci_int.h"
  26. #ifdef ZTS
  27. #include <TSRM/TSRM.h>
  28. #endif
  29. /* {{{ pdo_oci_module_entry */
  30. static const zend_module_dep pdo_oci_deps[] = {
  31. ZEND_MOD_REQUIRED("pdo")
  32. ZEND_MOD_END
  33. };
  34. zend_module_entry pdo_oci_module_entry = {
  35. STANDARD_MODULE_HEADER_EX, NULL,
  36. pdo_oci_deps,
  37. "PDO_OCI",
  38. NULL,
  39. PHP_MINIT(pdo_oci),
  40. PHP_MSHUTDOWN(pdo_oci),
  41. PHP_RINIT(pdo_oci),
  42. NULL,
  43. PHP_MINFO(pdo_oci),
  44. PHP_PDO_OCI_VERSION,
  45. STANDARD_MODULE_PROPERTIES
  46. };
  47. /* }}} */
  48. #ifdef COMPILE_DL_PDO_OCI
  49. ZEND_GET_MODULE(pdo_oci)
  50. #endif
  51. const ub4 PDO_OCI_INIT_MODE =
  52. #if 0 && defined(OCI_SHARED)
  53. /* shared mode is known to be bad for PHP */
  54. OCI_SHARED
  55. #else
  56. OCI_DEFAULT
  57. #endif
  58. #ifdef OCI_OBJECT
  59. |OCI_OBJECT
  60. #endif
  61. #ifdef ZTS
  62. |OCI_THREADED
  63. #endif
  64. ;
  65. /* true global environment */
  66. OCIEnv *pdo_oci_Env = NULL;
  67. #ifdef ZTS
  68. /* lock for pdo_oci_Env initialization */
  69. static MUTEX_T pdo_oci_env_mutex;
  70. #endif
  71. /* {{{ PHP_MINIT_FUNCTION */
  72. PHP_MINIT_FUNCTION(pdo_oci)
  73. {
  74. REGISTER_PDO_CLASS_CONST_LONG("OCI_ATTR_ACTION", (zend_long)PDO_OCI_ATTR_ACTION);
  75. REGISTER_PDO_CLASS_CONST_LONG("OCI_ATTR_CLIENT_INFO", (zend_long)PDO_OCI_ATTR_CLIENT_INFO);
  76. REGISTER_PDO_CLASS_CONST_LONG("OCI_ATTR_CLIENT_IDENTIFIER", (zend_long)PDO_OCI_ATTR_CLIENT_IDENTIFIER);
  77. REGISTER_PDO_CLASS_CONST_LONG("OCI_ATTR_MODULE", (zend_long)PDO_OCI_ATTR_MODULE);
  78. REGISTER_PDO_CLASS_CONST_LONG("OCI_ATTR_CALL_TIMEOUT", (zend_long)PDO_OCI_ATTR_CALL_TIMEOUT);
  79. if (FAILURE == php_pdo_register_driver(&pdo_oci_driver)) {
  80. return FAILURE;
  81. }
  82. // Defer OCI init to PHP_RINIT_FUNCTION because with php-fpm,
  83. // NLS_LANG is not yet available here.
  84. #ifdef ZTS
  85. pdo_oci_env_mutex = tsrm_mutex_alloc();
  86. #endif
  87. return SUCCESS;
  88. }
  89. /* }}} */
  90. /* {{{ PHP_RINIT_FUNCTION */
  91. PHP_RINIT_FUNCTION(pdo_oci)
  92. {
  93. if (!pdo_oci_Env) {
  94. #ifdef ZTS
  95. tsrm_mutex_lock(pdo_oci_env_mutex);
  96. if (!pdo_oci_Env) { // double-checked locking idiom
  97. #endif
  98. #ifdef HAVE_OCIENVCREATE
  99. OCIEnvCreate(&pdo_oci_Env, PDO_OCI_INIT_MODE, NULL, NULL, NULL, NULL, 0, NULL);
  100. #else
  101. OCIInitialize(PDO_OCI_INIT_MODE, NULL, NULL, NULL, NULL);
  102. OCIEnvInit(&pdo_oci_Env, OCI_DEFAULT, 0, NULL);
  103. #endif
  104. #ifdef ZTS
  105. }
  106. tsrm_mutex_unlock(pdo_oci_env_mutex);
  107. #endif
  108. }
  109. return SUCCESS;
  110. }
  111. /* }}} */
  112. /* {{{ PHP_MSHUTDOWN_FUNCTION */
  113. PHP_MSHUTDOWN_FUNCTION(pdo_oci)
  114. {
  115. php_pdo_unregister_driver(&pdo_oci_driver);
  116. if (pdo_oci_Env) {
  117. OCIHandleFree((dvoid*)pdo_oci_Env, OCI_HTYPE_ENV);
  118. }
  119. #ifdef ZTS
  120. tsrm_mutex_free(pdo_oci_env_mutex);
  121. #endif
  122. return SUCCESS;
  123. }
  124. /* }}} */
  125. /* {{{ PHP_MINFO_FUNCTION */
  126. PHP_MINFO_FUNCTION(pdo_oci)
  127. {
  128. php_info_print_table_start();
  129. php_info_print_table_header(2, "PDO Driver for OCI 8 and later", "enabled");
  130. php_info_print_table_end();
  131. }
  132. /* }}} */