我遇到了相同的问题,并在不使用XDebug的情况下解决了它。很遗憾,我没有找到使用XDebug的方法。就好像它不关心任何分叉进程一样。
我通过使用
Xhprof进行剖析和
Xhgui进行日志检查来解决这个问题。 Xhprof是Facebook内部开发的一个很棒的工具,后来成为了开源软件。
很酷的是,你可以决定何时开始剖析和何时停止。这使你有能力解决我们的问题。
所以首先让我们安装它!
sudo pecl install xhprof-beta
如果您正在使用基于Debian的发行版,请确保您还安装了Graphviz。
sudo apt-get install graphviz
现在让我们来看一下代码。
$children = [];
do {
if (count($children) < $maxConsumers) {
$pid = pcntl_fork();
$children[] = $pid;
if ($pid == -1) {
throw new \RuntimeException('Could not fork process');
} else if ($pid === 0) {
if ($verbose) {
$output->writeln(sprintf('Child here (PID = %s)', posix_getpid()));
}
if ($xhProf) {
xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);
}
if ($xhProf) {
require_once('/var/www/xhgui/external/header.php');
}
exit;
} else {
if ($verbose) {
$output->writeln(sprintf('Parent here (PID = %s) spawned a new child (PID = %s)', posix_getpid(), $pid));
}
}
} else {
if ($verbose) {
$output->writeln(sprintf("Parent - spawned enough children, let's wait them..."));
}
$deadPID = pcntl_wait($status);
$children = array_diff($children, [$deadPID]);
} while (true);
while (($pid = pcntl_waitpid(0, $status)) != -1) {
if ($verbose) {
$status = pcntl_wexitstatus($status);
$output->writeln(sprintf("Child (PID %d) terminated. Status is %s.", $pid, $status));
}
}
为了检查您的日志,您还需要正确配置Xhgui。您可能还需要一个虚拟主机。
有关所有所需的配置和参考信息: