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