@@ -491,6 +491,23 @@ extern "C" fn rinit(_type: c_int, _module_number: c_int) -> ZendResult {
491
491
locals. system_settings = system_settings;
492
492
} ) ;
493
493
494
+ // Preloading happens before zend_post_startup_cb is called for the first
495
+ // time. When preloading is enabled and a non-root user is used for
496
+ // php-fpm, there is fork that happens. In the past, having the profiler
497
+ // enabled at this time would cause php-fpm eventually hang once the
498
+ // Profiler's channels were full; this has been fixed. See:
499
+ // https://github.com/DataDog/dd-trace-php/issues/1919
500
+ //
501
+ // There are a few ways to handle this preloading scenario with the fork,
502
+ // but the simplest is to not enable the profiler until the engine's
503
+ // startup is complete. This means the preloading will not be profiled,
504
+ // but this should be okay.
505
+ #[ cfg( php_preload) ]
506
+ if !unsafe { bindings:: ddog_php_prof_is_post_startup ( ) } {
507
+ debug ! ( "zend_post_startup_cb hasn't happened yet; not enabling profiler." ) ;
508
+ return ZendResult :: Success ;
509
+ }
510
+
494
511
// SAFETY: still safe to access in rinit after first_rinit.
495
512
let system_settings = unsafe { system_settings. as_mut ( ) } ;
496
513
@@ -531,23 +548,6 @@ extern "C" fn rinit(_type: c_int, _module_number: c_int) -> ZendResult {
531
548
exception:: exception_profiling_first_rinit ( ) ;
532
549
} ) ;
533
550
534
- // Preloading happens before zend_post_startup_cb is called for the first
535
- // time. When preloading is enabled and a non-root user is used for
536
- // php-fpm, there is fork that happens. In the past, having the profiler
537
- // enabled at this time would cause php-fpm eventually hang once the
538
- // Profiler's channels were full; this has been fixed. See:
539
- // https://github.com/DataDog/dd-trace-php/issues/1919
540
- //
541
- // There are a few ways to handle this preloading scenario with the fork,
542
- // but the simplest is to not enable the profiler until the engine's
543
- // startup is complete. This means the preloading will not be profiled,
544
- // but this should be okay.
545
- #[ cfg( php_preload) ]
546
- if !unsafe { bindings:: ddog_php_prof_is_post_startup ( ) } {
547
- debug ! ( "zend_post_startup_cb hasn't happened yet; not enabling profiler." ) ;
548
- return ZendResult :: Success ;
549
- }
550
-
551
551
Profiler :: init ( system_settings) ;
552
552
553
553
if system_settings. profiling_enabled {
@@ -631,6 +631,11 @@ extern "C" fn rshutdown(_type: c_int, _module_number: c_int) -> ZendResult {
631
631
#[ cfg( debug_assertions) ]
632
632
trace ! ( "RSHUTDOWN({_type}, {_module_number})" ) ;
633
633
634
+ #[ cfg( php_preload) ]
635
+ if !unsafe { bindings:: ddog_php_prof_is_post_startup ( ) } {
636
+ return ZendResult :: Success ;
637
+ }
638
+
634
639
profiling:: stack_walking:: rshutdown ( ) ;
635
640
636
641
REQUEST_LOCALS . with ( |cell| {
0 commit comments