pdf — PHP-демон PCNTL, возможное пересечение памяти

У меня есть PHP-демон, который запускает Magento в форках и печатает некоторые PDF-файлы.
Пожалуйста, найдите код основного процесса ниже:

class Generate_Pdf_New_Command extends Mage_Shell_Abstract
{
const SLEEP_TIME_SEC = 0.2;
const TIME_LIMIT = 600;
protected $_startTime;
protected $_childProcessList = [];

public function __construct()
{
$this->_parseArgs();
$this->_validate();
}

public function run()
{
$this->_startTime = time();
while (true) {
usleep(self::SLEEP_TIME_SEC * 1000);
$current = time();
if ($current - $this->_startTime >= self::TIME_LIMIT) {
exit(0);
}

$pid = pcntl_fork();
if ($pid === -1) {
$this->_printErr('Can\'t use forks.');
exit(0);
}

if ($pid) {
$this->_processMain($pid);
continue;
}

$this->_processChild();
exit(0);
}
}

protected function _processMain($pid)
{
$this->_childProcessList[$pid] = true;
if ($this->_canFork()) {
return;
}
$signPid = pcntl_wait($status);
if (isset($this->_childProcessList[$signPid])) {
unset($this->_childProcessList[$signPid]);
} else {
$this->_childProcessList = [];
}
}

protected function _processChild()
{
try {
(new Generate_Pdf)->run();
} catch (Throwable $e) {
$this->_printErr($e->getMessage());
}
}

protected function _canFork()
{
return count($this->_childProcessList) < $this->getArg('children');
}

protected function _printLn($msg)
{
fwrite(STDOUT, $msg.PHP_EOL);
}

protected function _printErr($msg)
{
fwrite(STDERR, $msg.PHP_EOL);
}
}

Класс Generate_Pdf расширяет Mage_Shell_Abstract, но не переопределяет конструктор, поэтому он запускает Magento. Mage_Shell_Abstract используется в основном процессе только для работы с аргументами и проверки.
В целом работает нормально, но иногда мы сталкиваемся с некоторыми пересечениями в PDF-файлах результатов. Я понятия не имею о причине и был бы очень признателен, если бы у кого-то была такая.

0

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы [email protected]