Php &引用;序列化';关闭';“不允许”;在Symfony应用程序中调用\线程类(pthreads)时
我无法使PthreadsV3与Symfony 4.1.4一起工作 在一个PHP文件中运行一个简单的概念验证可以正常工作,但是当移动到SymfonyPhp &引用;序列化';关闭';“不允许”;在Symfony应用程序中调用\线程类(pthreads)时,php,multithreading,pthreads,threadpool,symfony4,Php,Multithreading,Pthreads,Threadpool,Symfony4,我无法使PthreadsV3与Symfony 4.1.4一起工作 在一个PHP文件中运行一个简单的概念验证可以正常工作,但是当移动到SymfonyContainerWareCommand时,我会遇到以下错误 致命错误:未捕获异常:“Closure”的序列化不正确 在[无活动文件]:0堆栈跟踪中允许: 0{main}在第0行的[无活动文件]中抛出 我觉得这与Symfony容器在\Threaded类中被复制和序列化有关。在中提出建议后,我尝试在services.yaml的排除列表中排除线程、线程和工
ContainerWareCommand
时,我会遇到以下错误
致命错误:未捕获异常:“Closure”的序列化不正确
在[无活动文件]:0堆栈跟踪中允许:
0{main}在第0行的[无活动文件]中抛出
我觉得这与Symfony容器在\Threaded类中被复制和序列化有关。在中提出建议后,我尝试在services.yaml的排除列表中排除线程
、线程
和工作者
名称空间,但没有解决问题
有人能解释一下我做错了什么吗。我目前不确定是否可以使用带有Pthreads的Symfony 4
以下代码可从单个php文件运行。
在symfony(2.8)命令中,me既不能使线程(3)工作。
我的php版本:
PHP 7.2.9-dev(cli)(构建时间:2018年9月5日14:13:58)(ZTS)
但作为替代解决方案:
- 创建一个具有线程逻辑的简单php文件
- 使用
我也有同样的问题,但我的symfony版本2.8和php版本是PHP7.2.9-dev(cli)(构建时间:2018年9月5日14:13:58)(ZTS)当任务使用submit方法添加到池中时,它会抛出该消息。
<?php
$pool = new \Pool(4, TickerWorker::class, []);
for ($i = 0; $i < 10; $i++) {
$pool->submit(new TickerTask($i));
}
while ($pool->collect()) ;
$pool->shutdown();
echo "Pool done\n";
class TickerWorker extends \Worker
{
public function __construct()
{
}
}
class TickerTask extends \Threaded
{
protected $complete;
private $i;
public function __construct($i)
{
echo "$i start\n";
$this->i = $i;
$this->complete = false;
}
public function run()
{
sleep(rand(1, 3));
echo "$this->i done\n";
$this->complete = true;
}
public function isComplete()
{
return $this->complete;
}
}
<?php
namespace App\Command;
use App\Pthread\TickerTask;
use App\Pthread\TickerWorker;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
/**
* Where App\Pthread\TickerWorker and App\Pthread\TickerTask
* are the classes as defined in the working example
*/
class CoconutTestCommand extends ContainerAwareCommand
{
protected static $defaultName = 'coconut:test';
protected function execute(InputInterface $input, OutputInterface $output)
{
$pool = new \Pool(4, TickerWorker::class, []);
for ($i = 0; $i < 10; $i++) {
$pool->submit(new TickerTask($i));
}
while ($pool->collect()) ;
$pool->shutdown();
echo "Pool done\n";
}
}