1

我正在尝试从 CLI 的 Symfony 4 命令初始化线程,但得到“总线错误:10”。

<?php

namespace App\Command;

use Thread;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class LaunchMyAppCommand extends Command
{
    protected function configure()
    {
        $this->setName('app:launch-myapp');
        $this->setDescription('Launches app.');
        $this->setHelp('This launches app...');
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $thread = new class extends Thread {
            public function run() {
                file_put_contents('/tmp/myapp.log', 'My entry', FILE_APPEND);
            }
        };

        $thread->start();
    }
}
$ php bin/console app:launch-myapp
Bus error: 10

我试图将初始化部分复制到一个单独的文件中以进行调试,这很有效。所以 pthreads 似乎安装正确。此外,根据 phpinfo() 启用线程安全。

<?php

$thread = new class extends Thread {
    public function run() {
        file_put_contents('/tmp/home.log', 'My entry', FILE_APPEND);
    }
};

$thread->start();
4

0 回答 0