26
26
#endif
27
27
28
28
#include "php.h"
29
+ #include "SAPI.h"
29
30
30
31
#define PHP_XML_INTERNAL
31
32
#include "zend_variables.h"
53
54
54
55
/* a true global for initialization */
55
56
static int _php_libxml_initialized = 0 ;
57
+ static int _php_libxml_per_request_initialization = 1 ;
56
58
57
59
typedef struct _php_libxml_func_handler {
58
60
php_libxml_export_node export_func ;
@@ -636,22 +638,55 @@ static PHP_MINIT_FUNCTION(libxml)
636
638
INIT_CLASS_ENTRY (ce , "LibXMLError" , NULL );
637
639
libxmlerror_class_entry = zend_register_internal_class (& ce TSRMLS_CC );
638
640
641
+ if (sapi_module .name ) {
642
+ static const char * const supported_sapis [] = {
643
+ "cgi-fcgi" ,
644
+ "fpm-fcgi" ,
645
+ "litespeed" ,
646
+ NULL
647
+ };
648
+ const char * const * sapi_name ;
649
+
650
+ for (sapi_name = supported_sapis ; * sapi_name ; sapi_name ++ ) {
651
+ if (strcmp (sapi_module .name , * sapi_name ) == 0 ) {
652
+ _php_libxml_per_request_initialization = 0 ;
653
+ break ;
654
+ }
655
+ }
656
+ }
657
+
658
+ if (!_php_libxml_per_request_initialization ) {
659
+ /* report errors via handler rather than stderr */
660
+ xmlSetGenericErrorFunc (NULL , php_libxml_error_handler );
661
+ xmlParserInputBufferCreateFilenameDefault (php_libxml_input_buffer_create_filename );
662
+ xmlOutputBufferCreateFilenameDefault (php_libxml_output_buffer_create_filename );
663
+ }
664
+
639
665
return SUCCESS ;
640
666
}
641
667
642
668
643
669
static PHP_RINIT_FUNCTION (libxml )
644
670
{
645
- /* report errors via handler rather than stderr */
646
- xmlSetGenericErrorFunc (NULL , php_libxml_error_handler );
647
- xmlParserInputBufferCreateFilenameDefault (php_libxml_input_buffer_create_filename );
648
- xmlOutputBufferCreateFilenameDefault (php_libxml_output_buffer_create_filename );
671
+ if (_php_libxml_per_request_initialization ) {
672
+ /* report errors via handler rather than stderr */
673
+ xmlSetGenericErrorFunc (NULL , php_libxml_error_handler );
674
+ xmlParserInputBufferCreateFilenameDefault (php_libxml_input_buffer_create_filename );
675
+ xmlOutputBufferCreateFilenameDefault (php_libxml_output_buffer_create_filename );
676
+ }
649
677
return SUCCESS ;
650
678
}
651
679
652
680
653
681
static PHP_MSHUTDOWN_FUNCTION (libxml )
654
682
{
683
+ if (!_php_libxml_per_request_initialization ) {
684
+ xmlSetGenericErrorFunc (NULL , NULL );
685
+ xmlSetStructuredErrorFunc (NULL , NULL );
686
+
687
+ xmlParserInputBufferCreateFilenameDefault (NULL );
688
+ xmlOutputBufferCreateFilenameDefault (NULL );
689
+ }
655
690
php_libxml_shutdown ();
656
691
657
692
return SUCCESS ;
@@ -661,11 +696,13 @@ static PHP_MSHUTDOWN_FUNCTION(libxml)
661
696
static PHP_RSHUTDOWN_FUNCTION (libxml )
662
697
{
663
698
/* reset libxml generic error handling */
664
- xmlSetGenericErrorFunc (NULL , NULL );
665
- xmlSetStructuredErrorFunc (NULL , NULL );
699
+ if (_php_libxml_per_request_initialization ) {
700
+ xmlSetGenericErrorFunc (NULL , NULL );
701
+ xmlSetStructuredErrorFunc (NULL , NULL );
666
702
667
- xmlParserInputBufferCreateFilenameDefault (NULL );
668
- xmlOutputBufferCreateFilenameDefault (NULL );
703
+ xmlParserInputBufferCreateFilenameDefault (NULL );
704
+ xmlOutputBufferCreateFilenameDefault (NULL );
705
+ }
669
706
670
707
if (LIBXML (stream_context )) {
671
708
zval_ptr_dtor (& LIBXML (stream_context ));
0 commit comments