3838#include "php.h"
3939#include "php_ini.h"
4040#include "zend_exceptions.h"
41+ #include "zend_interfaces.h"
4142#include "php_apm.h"
4243#include "backtrace.h"
4344#include "ext/standard/info.h"
5354#ifdef APM_DRIVER_SOCKET
5455# include "driver_socket.h"
5556#endif
57+ #ifdef APM_DRIVER_HTTP
58+ #include "driver_http.h"
59+ #endif
5660
5761ZEND_DECLARE_MODULE_GLOBALS (apm );
5862static PHP_GINIT_FUNCTION (apm );
@@ -240,6 +244,25 @@ PHP_INI_BEGIN()
240244 /* process silenced events? */
241245 STD_PHP_INI_BOOLEAN ("apm.socket_process_silenced_events" , "1" , PHP_INI_PERDIR , OnUpdateBool , socket_process_silenced_events , zend_apm_globals , apm_globals )
242246#endif
247+
248+ #ifdef APM_DRIVER_HTTP
249+ /* Boolean controlling whether the driver is active or not */
250+ STD_PHP_INI_BOOLEAN ("apm.http_enabled" , "1" , PHP_INI_ALL , OnUpdateBool , http_enabled , zend_apm_globals , apm_globals )
251+ /* Boolean controlling the collection of stats */
252+ STD_PHP_INI_BOOLEAN ("apm.http_stats_enabled" , "1" , PHP_INI_ALL , OnUpdateBool , http_stats_enabled , zend_apm_globals , apm_globals )
253+ /* Control which exceptions to collect (0: none exceptions collected, 1: collect uncaught exceptions (default), 2: collect ALL exceptions) */
254+ STD_PHP_INI_ENTRY ("apm.http_exception_mode" ,"1" , PHP_INI_PERDIR , OnUpdateLongGEZero , http_exception_mode , zend_apm_globals , apm_globals )
255+ /* error_reporting of the driver */
256+ STD_PHP_INI_ENTRY ("apm.http_error_reporting" , NULL , PHP_INI_ALL , OnUpdateAPMhttpErrorReporting , http_error_reporting , zend_apm_globals , apm_globals )
257+ /* process silenced events? */
258+ STD_PHP_INI_BOOLEAN ("apm.http_process_silenced_events" , "1" , PHP_INI_PERDIR , OnUpdateBool , http_process_silenced_events , zend_apm_globals , apm_globals )
259+ STD_PHP_INI_ENTRY ("apm.http_request_timeout" , "1000" , PHP_INI_ALL , OnUpdateLong , http_request_timeout , zend_apm_globals , apm_globals )
260+ STD_PHP_INI_ENTRY ("apm.http_server" , "http://localhost" , PHP_INI_ALL , OnUpdateString , http_server , zend_apm_globals , apm_globals )
261+ STD_PHP_INI_ENTRY ("apm.http_client_certificate" , NULL , PHP_INI_ALL , OnUpdateString , http_client_certificate , zend_apm_globals , apm_globals )
262+ STD_PHP_INI_ENTRY ("apm.http_client_key" , NULL , PHP_INI_ALL , OnUpdateString , http_client_key , zend_apm_globals , apm_globals )
263+ STD_PHP_INI_ENTRY ("apm.http_certificate_authorities" , NULL , PHP_INI_ALL , OnUpdateString , http_certificate_authorities , zend_apm_globals , apm_globals )
264+ STD_PHP_INI_ENTRY ("apm.http_max_backtrace_length" , "0" , PHP_INI_ALL , OnUpdateLong , http_max_backtrace_length , zend_apm_globals , apm_globals )
265+ #endif
243266PHP_INI_END ()
244267
245268static PHP_GINIT_FUNCTION (apm )
@@ -272,6 +295,9 @@ static PHP_GINIT_FUNCTION(apm)
272295 * next = apm_driver_socket_create ();
273296 next = & (* next )-> next ;
274297#endif
298+ #ifdef APM_DRIVER_HTTP
299+ * next = apm_driver_http_create ();
300+ #endif
275301}
276302
277303static void recursive_free_driver (apm_driver_entry * * driver )
@@ -487,9 +513,11 @@ void apm_error_cb(int type, const char *error_filename, const uint error_lineno,
487513
488514void apm_throw_exception_hook (zval * exception TSRMLS_DC )
489515{
490- zval * message , * file , * line ;
491516#if PHP_VERSION_ID >= 70000
517+ zval message , file , line ;
492518 zval rv ;
519+ #else
520+ zval * message , * file , * line ;
493521#endif
494522 zend_class_entry * default_ce ;
495523
@@ -501,16 +529,20 @@ void apm_throw_exception_hook(zval *exception TSRMLS_DC)
501529 default_ce = zend_exception_get_default (TSRMLS_C );
502530
503531#if PHP_VERSION_ID >= 70000
504- message = zend_read_property ( default_ce , exception , "message" , sizeof ( "message" ) - 1 , 0 , & rv );
505- file = zend_read_property ( default_ce , exception , "file" , sizeof ( "file" ) - 1 , 0 , & rv );
506- line = zend_read_property ( default_ce , exception , "line" , sizeof ( "line" ) - 1 , 0 , & rv );
532+ zend_call_method_with_0_params ( exception , default_ce , NULL , "getmessage" , & message );
533+ zend_call_method_with_0_params ( exception , default_ce , NULL , "getfile" , & file );
534+ zend_call_method_with_0_params ( exception , default_ce , NULL , "getline" , & line );
507535#else
508536 message = zend_read_property (default_ce , exception , "message" , sizeof ("message" )- 1 , 0 TSRMLS_CC );
509537 file = zend_read_property (default_ce , exception , "file" , sizeof ("file" )- 1 , 0 TSRMLS_CC );
510538 line = zend_read_property (default_ce , exception , "line" , sizeof ("line" )- 1 , 0 TSRMLS_CC );
511539#endif
512540
541+ #if PHP_VERSION_ID >= 70000
542+ process_event (APM_EVENT_EXCEPTION , E_EXCEPTION , Z_STRVAL (file ), Z_LVAL (line ), Z_STRVAL (message ) TSRMLS_CC );
543+ #else
513544 process_event (APM_EVENT_EXCEPTION , E_EXCEPTION , Z_STRVAL_P (file ), Z_LVAL_P (line ), Z_STRVAL_P (message ) TSRMLS_CC );
545+ #endif
514546 }
515547}
516548
0 commit comments