Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can XDebug debug a PHP CLI script that uses pcntl_fork()?

Tags:

php

fork

xdebug

I have a CLI script written in PHP that I am trying to debug with XDebug. The debugger is working, as I can step through the code as it initializes, but it breaks down after the process forks, becomes a daemon, and lets the original process exit. My theory is the XDebug socket is closing when the initial process terminates, which leaves the daemon and any processes it forks without an open socket to my XDebug listener.

Database connections can be reconnected or even created after the fork, but XDebug appears to have no such option in their function list. Can the XDebug socket survive the initial process exiting or be reestablished after the a call to pcntl_fork()? Is there any workaround for this?

like image 976
jimp Avatar asked Dec 01 '25 22:12

jimp


1 Answers

No, Xdebug does not handle sockets that span multiple processes. Your theory is sort of right. A socket simply can't be easily duplicated upon a fork, and Xdebug does not handle this currently. A socket is also closed when a process ends.

There is an issue (https://bugs.xdebug.org/view.php?id=938), on which you commented. It is possible to fix this—I've done a similar thing with the old MongoDB extension—but it's not high on my priority list.

like image 85
Derick Avatar answered Dec 03 '25 15:12

Derick



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!