我正在尝试从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
我试图将初始化部分复制到一个单独的文件中以便进行调试,这有效。所以pthread似乎安装正确。此外,根据phpinfo()线程安全性已启用。
<?php
$thread = new class extends Thread {
public function run() {
file_put_contents('/tmp/home.log', 'My entry', FILE_APPEND);
}
};
$thread->start();