F
F
frontendo2017-08-02 18:52:39
PHP
frontendo, 2017-08-02 18:52:39

How to properly start php daemon from php script?

I run
shell_exec("php time.php");
but the current script hangs. It is necessary to start somehow so that shell_exec does not wait, but immediately returns control to the script

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey, 2017-08-02
@frontendo

public function run() {
        $set = array(
            'command' => 'work',
        );
        $this->demon = $this->setParam($set);
        chdir($this->demon['dir']);
        if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
            /* Система Windows */
            pclose(popen('start /B cmd /C "php '. $this->demon['name'] .' >NUL 2>NUL"', 'r'));
        } else {
            /* Система *nix */
            $command = 'php -f ' . $this->demon['name'] . ' > /dev/null 2>&1 &';
            exec($command);
        }
    }

Taken from here

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question