krakjoe / tombs

Detect unused code in production
Other
433 stars 20 forks source link

shared memory and io socket shut down immediately when php-fpm is set to daemonize #24

Open mreishus opened 5 months ago

mreishus commented 5 months ago

The extension works fine when php-fpm is run in the foreground, but when it's set to daemonize, the zend_tombs_shutdown() funtion is run immediately, meaning there is no socket to listen to.

When php-fpm is set to daemonize, it forks and then runs fpm_cleanups_run() (link).

For example, let's say you run /usr/bin/php-fpm -D --fpm-config /etc/php/php-fpm.conf. This initially starts PID=99296. It will fork and create PID=99299, which will be the new master working in the background, while 99296 will quickly die and run the zend_tombs_shutdown().

I see the zend_tombs_startup() and zend_tombs_shutdown() functions running on 99296 directly after starting php-fpm with daemonize. This is on the outer process whos only job it is to fork into the daemonized process - while 99299, the daemonzied process, does not run any of the zend lifecycle code. Ideally, I'd like to move the zend_tombs_startup() call until after php-fpm forks, to the 99299 process, but I'm not sure how to do that. Anyone know how?