F
F
ff0xff2018-10-21 05:51:52
symfony
ff0xff, 2018-10-21 05:51:52

How to start a Thread in symfony 4?

Good day to all, the task arose to run in parallel the processing of some operations from the CLI written in symfony 4 the
server was built with zts support test examples Thread worked fine
(test examples)

  • https://www.smddzcy.com/2016/01/tutorial-multi-thr...
  • blog.programster.org/ubuntu16-04-compile-php-7-2-w...

But when it comes to using it in a framework, there are problems.
When you run the code:
namespace App\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use App\Worker\Worker;
class TestCommand extends Command
{
    protected function configure()
    {
        $this->setName('app:test')
            ->setDescription('Description)
            ->setHelp('help ')
        ;
    }
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $thread = new Worker();
        $thread->start() && $thread->join();
    }

  
}

worker.php
namespace App\Worker;

class Worker extends \Thread
{
    private $value;
    private $executor;

    public function __construct()
    {

    }

    public function run()
    {
        echo "asd";

    }
}

An error occurs:
PHP Fatal error: Uncaught Exception: Serialization of 'Closure' is not allowed in [no active file]:0
Stack trace:
#0 {main}
thrown in [no active file] on line 0
/home/master/php-src- php-7.2.2/main/main.c(1248) : Bailed out without a bailout address!

Found related questions:
  • Pthreads, Laravel Commands and Closure - How to fix Serialization of 'Closure' is not allowed?
  • https://github.com/krakjoe/pthreads/issues/671
  • https://github.com/symfony/symfony/issues/28339

But I still don't understand how to solve this problem.
I also came across this code:
https://github.com/krakjoe/pthreads-autoloading-co...
But I did not understand how to apply it regarding my case.
Please tell me how to fix this bug? who faced this problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
ff0xff, 2018-10-28
@ff0xff

This method helped me, there the dude tells everything in detail why symfony does not work and how to fix it.
https://github.com/krakjoe/pthreads-autoloading-co...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question