i try to start a simple thread (create with the pthreads ext v3 for php 7) within a Symfony2 command. But i wonder if i get an error because of non serializable closure (i don't use a closure anywhere).
The Command:
<?php
public function execute(InputInterface $input, OutputInterface $output)
{
$job = new JobThread();
$output->writeln('Starting thread...');
$job->start();
$output->writeln('Waiting for thread to finish executing...');
$job->join();
$output->writeln('Thread finished');
}
The JobThread class
<?php
class JobThread extends Thread
{
public function run()
{
echo 'Run' . PHP_EOL;
sleep(3);
echo 'End' . PHP_EOL;
}
}
If i execute the command, i get the following output:
Starting thread...
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
If i start the thread outside of the command context...
$job = new ThreadJob();
echo 'Starting thread...' . PHP_EOL;
$job->start();
echo 'Waiting for thread to finish executing...' . PHP_EOL;
$job->join();
echo 'Thread finished' . PHP_EOL;
i get the expected output:
Starting thread...
Waiting for thread to finish executing...
Run
End
Thread finished
Where is the point of failure?