What I need to do is process multiple requests that are pending in a database, using PHP.
What I'm currently trying to do is: When my cronjob runs. I want to call a file "process_a.php" 10 times, instantly, without waiting for it to finish processing (process_a.php could take a few minutes).
I tried to do this using CURL. But right when my cronjob calls process_a.php, it waits for it to finish processing and return before calling another process_a.php file.
I even tried putting code in process_a.php to close the connection instantly, then continue processing in the background. but the cronjob still waited for it to finish.
I just want the same file being executed 10 times at once, you know, like if 10 different users were to request the index.php page of my website... Any ideas!?
Do you have full cron available, or are you only able to specify php files?
You might be able to use xargs to fork 10 processes with the
-P
argumentFork into 10 processes:
... but that process_a.php could do anything your website does, so, rather then calling a page, why not do the actual work the page request would result in? And let the webserver just continue to be, you know, a webserver instead of a bloated script-repo.
As told by @Brad curl-multi-exec should be an option.
http://php.net/manual/en/function.curl-multi-exec.php
I tested this script by calling another script below :
and here are the results, each handle differing by microseconds in execution time.