Answer the question
In order to leave comments, you need to log in
Is it possible to run Laravel console commands on different threads?
There are two console commands check and stream. Check is the parent process and stream is the child.
I am using Reactphp.
check
public function handle()
{
$stream = $this->argument('stream');
$offset = 0;
//$v = new child();
$loop = \React\EventLoop\Factory::create();
for ($i = 1; $i <= $stream; $i++) {
$process = new \React\ChildProcess\Process(Artisan::call('proxy:stream', ['stream' => $i]));
$process->on('exit', function ($exitCode, $termSignal) {
echo "Child exit\n";
});
$loop->addTimer(0.5, function ($timer) use ($process) {
$process->start($timer->getLoop());
$process->stdout->on('data', function ($output) {
echo "{$output}";
});
});
$offset = 2 * $i;
}
$loop->addPeriodicTimer(5, function ($timer) {
echo "Parent cannot be blocked by child\n";
});
$loop->run();
}
public function handle()
{
$check = new CheckProxy();
$stream = $this->argument('stream');
$offset = $this->argument('offset');
for($i=0; $i< 10; $i++) {
echo "Stream ".$stream." - ".$i."\n";
sleep(1);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question