A
A
Alexander2021-05-28 14:30:59
PHP
Alexander, 2021-05-28 14:30:59

How to implement the launch of console commands in php?

Hello, the question is, how do I implement the launch of console commands in php, I use proc_open, the command is executed in 5-20 seconds, then everything is fine, and if more than 30, then it’s not clear what’s going on here is a code snippet with the implementation

$item->setStatus(Queue::PROCESSING);
        $cmd = $item->task->getCMD();
        $cmd = escapeshellcmd($cmd);
        $path = 'Путь до лог файла';
        $cdw = 'Путь где будут запускаться команды';
        $descript = [
            ["pipe", "r"], // stdin - канал, из которого дочерний процесс будет читать
            ["file", $path, "w"], // stdout - канал, в который дочерний процесс будет записывать
            ["file", $path, "a"] // stderr - файл для записи
        ];
        $this->proc = proc_open($cmd, $descript,$pipes, $cdw);
        $status = $this->getStatus();
        $item->setPID($status['pid']);
        proc_close($this->proc);

        //все что ниже если выполнение занимает больше 30 секунд отпадает если же секунд 15 выполняется
        $message = file_get_contents($path);
        $item->setMessage($message);
        $taskStatus = $this->checkError($message) ? Queue::ERROR : Queue::READY;
        $item->setStatus($taskStatus);

I can't figure out what is the reason? something with php? with a config maybe with something else? and most importantly how to solve the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Slava Rozhnev, 2021-05-28
@riki13

Here is the answer: https://www.php.net/manual/en/function.set-time-li...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question