Hi folks,
I have an app with console commands tied to CRONTAB. The console command basically queries a table to find out the last time named scripts were run i.e. each time of the scripts in the table is run, it updates the table to reflect when it was last run. Some of these scripts need to be run even minute, some every 5 mins and so on.
So, I have something like this: -
$arrValidScripts = Yii::$app->db->createCommand("
SELECT script_name
FROM script
WHERE
(
(
(($fltTimeNow + 20) >= (last_attempt_run_date + (frequency_minute * 60)))
OR
last_attempt_run_date = 0
)
)
ORDER BY script_name
")->queryAll();
foreach($arrValidScripts as $arrValidScript):
$strScriptName = $arrValidScript['script_name'];
echo $strScriptName;
exec(Controller::run("console-script/run", $params = [$strScriptName]));
endforeach;
So, that’s all working fine.
Here’s the catch - I REALLY want to be able to run all the scripts simultaneously as some of them taking a fraction of a second, others take over a minute and this is affecting the quality of the service provided by the app. I was lead to believe that using exec() would accomplish this, but it doesnt seem to in this case.
Can anyone help? Or is multithreading just impossible in PHP?