I have a PHP script "cron.php" to run by Task scheduler, which is on Windows 10 (XAMPP PHP 7.4.3). The script calls "process_1.php" and "process_2.php". As shown in code below, the 2nd process will run ONLY after the 1st process has completed.
Is there a way to run both processes concurrently?
In a browser, I could open two windows then launch 2 processes, and they would run separately and concurrently.
It seems the "include", "cURL", and "exec" all run two processes sequentially, as I tested below individually.
<?php
// cron.php
// 1st test
include "process_1.php";
include "process_2.php";
// 2nd test
exec (php.exe -f process_1.php);
exec (php.exe -f process_1.php);
// 3rd test
$curl_obj = new curl_obj ();
$curl_obj.exec (url='process_1.php');
$curl_obj.exec (url='process_2.php');
?>
I could schedule 2 tasks to run "process_1.php" and "process_2.php" at the same time, to get exactly what I expect, in this way I don't even need "cron.php". But I am looking for a better solution. Otherwise, I will have to schedule 100 tasks if I have 100 processes. I hope one scheduled job could take care of all processes.
The benefit is time saving. Say each process takes 1 hour to complete, in cron job it will take 2 hours when running sequentially. If I could split them into 2 process running concurrently in scheduled job, it does not need two hours. When I had both processes running on separate browsers concurrently, it took 65 minutes to complete both.
So far I got to know following as possible solutions, and I will try them. Thank you for all responses!
- Thread
- Parallel
- curl_multi_exec
Thank you!