summaryrefslogtreecommitdiff
path: root/ext/libxml/libxml.c
diff options
context:
space:
mode:
authorDmitry Stogov <dmitry@php.net>2010-08-27 06:12:37 +0000
committerDmitry Stogov <dmitry@php.net>2010-08-27 06:12:37 +0000
commitd8bddb9665637d96f20dc4a2ae5668ba376f3b17 (patch)
treebfbe7a1864a65442be16952222fa5feb428ff4e1 /ext/libxml/libxml.c
parentcaffc1c9726e14a49d20678df454d1326b0962a0 (diff)
downloadphp-git-d8bddb9665637d96f20dc4a2ae5668ba376f3b17.tar.gz
In some SAPI (e.g. FastCGI) we don't need to setup and reset libxml callbacks on each request, we con do it only once. Probably the list of such SAPI may be extended.
Diffstat (limited to 'ext/libxml/libxml.c')
-rw-r--r--ext/libxml/libxml.c53
1 files changed, 45 insertions, 8 deletions
diff --git a/ext/libxml/libxml.c b/ext/libxml/libxml.c
index 83e879d044..8d07a18055 100644
--- a/ext/libxml/libxml.c
+++ b/ext/libxml/libxml.c
@@ -26,6 +26,7 @@
#endif
#include "php.h"
+#include "SAPI.h"
#define PHP_XML_INTERNAL
#include "zend_variables.h"
@@ -53,6 +54,7 @@
/* a true global for initialization */
static int _php_libxml_initialized = 0;
+static int _php_libxml_per_request_initialization = 1;
typedef struct _php_libxml_func_handler {
php_libxml_export_node export_func;
@@ -636,22 +638,55 @@ static PHP_MINIT_FUNCTION(libxml)
INIT_CLASS_ENTRY(ce, "LibXMLError", NULL);
libxmlerror_class_entry = zend_register_internal_class(&ce TSRMLS_CC);
+ if (sapi_module.name) {
+ static const char * const supported_sapis[] = {
+ "cgi-fcgi",
+ "fpm-fcgi",
+ "litespeed",
+ NULL
+ };
+ const char * const *sapi_name;
+
+ for (sapi_name = supported_sapis; *sapi_name; sapi_name++) {
+ if (strcmp(sapi_module.name, *sapi_name) == 0) {
+ _php_libxml_per_request_initialization = 0;
+ break;
+ }
+ }
+ }
+
+ if (!_php_libxml_per_request_initialization) {
+ /* report errors via handler rather than stderr */
+ xmlSetGenericErrorFunc(NULL, php_libxml_error_handler);
+ xmlParserInputBufferCreateFilenameDefault(php_libxml_input_buffer_create_filename);
+ xmlOutputBufferCreateFilenameDefault(php_libxml_output_buffer_create_filename);
+ }
+
return SUCCESS;
}
static PHP_RINIT_FUNCTION(libxml)
{
- /* report errors via handler rather than stderr */
- xmlSetGenericErrorFunc(NULL, php_libxml_error_handler);
- xmlParserInputBufferCreateFilenameDefault(php_libxml_input_buffer_create_filename);
- xmlOutputBufferCreateFilenameDefault(php_libxml_output_buffer_create_filename);
+ if (_php_libxml_per_request_initialization) {
+ /* report errors via handler rather than stderr */
+ xmlSetGenericErrorFunc(NULL, php_libxml_error_handler);
+ xmlParserInputBufferCreateFilenameDefault(php_libxml_input_buffer_create_filename);
+ xmlOutputBufferCreateFilenameDefault(php_libxml_output_buffer_create_filename);
+ }
return SUCCESS;
}
static PHP_MSHUTDOWN_FUNCTION(libxml)
{
+ if (!_php_libxml_per_request_initialization) {
+ xmlSetGenericErrorFunc(NULL, NULL);
+ xmlSetStructuredErrorFunc(NULL, NULL);
+
+ xmlParserInputBufferCreateFilenameDefault(NULL);
+ xmlOutputBufferCreateFilenameDefault(NULL);
+ }
php_libxml_shutdown();
return SUCCESS;
@@ -661,11 +696,13 @@ static PHP_MSHUTDOWN_FUNCTION(libxml)
static PHP_RSHUTDOWN_FUNCTION(libxml)
{
/* reset libxml generic error handling */
- xmlSetGenericErrorFunc(NULL, NULL);
- xmlSetStructuredErrorFunc(NULL, NULL);
+ if (_php_libxml_per_request_initialization) {
+ xmlSetGenericErrorFunc(NULL, NULL);
+ xmlSetStructuredErrorFunc(NULL, NULL);
- xmlParserInputBufferCreateFilenameDefault(NULL);
- xmlOutputBufferCreateFilenameDefault(NULL);
+ xmlParserInputBufferCreateFilenameDefault(NULL);
+ xmlOutputBufferCreateFilenameDefault(NULL);
+ }
if (LIBXML(stream_context)) {
zval_ptr_dtor(&LIBXML(stream_context));