Ответ 1
Я столкнулся с той же проблемой и решил без 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) {
// we are the child
if ($verbose) {
$output->writeln(sprintf('Child here (PID = %s)', posix_getpid()));
}
if ($xhProf) {
// here we enable xhprof thus the profiling starts
xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);
}
// DO YOUR MAGIC HERE!
if ($xhProf) {
// and here we call the xhgui header file that will
// stop xhprof and write all the gathered data into
// mongo or into a dedicated file
require_once('/var/www/xhgui/external/header.php');
}
exit;
} else {
// we are the parent
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 wait them..."));
}
$deadPID = pcntl_wait($status);
$children = array_diff($children, [$deadPID]);
} while (true);
// Waits for all remaining children
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. Вам также понадобится виртуальный хост.
Для всей необходимой конфигурации и для справки: