Environment
Development: Amazon EC2 instance.
Operational: Unknown at this time
Scenario
This is a *nix question but things start out in php, so please bear with me.
I'm trying to get php script (php_script_1) to to run another php script (php_script_2) in the background. This will allow php_script_1 to complete and return (with a suitable message to the user), having kicked off the lengthy php_script_2. The output of php_script_2 will be cached (in a database) for future use.
Progress to date
I have identified php's shell_exec() and a neat little "run_in_background" function wrapper to issue commands.
function run_in_background($Command, $Priority = 0){
if($Priority){
$PID = shell_exec("nohup nice -n $Priority $Command 2> /dev/null & echo $!");
}
else{
$PID = shell_exec("nohup $Command 2> /dev/null & echo $!");
}
return($PID);
}
With this, I can successfully call my php_script_2 (from php_script_1) with :-
...
$command = "php /var/www/make_objects.php";
$priority = 0;
$pid = run_in_background($command, $priority);//kick off background process
...
make_objects.php
is the main target of my current development effort so it isn't yet fully working, but at least I can call it.
What I need
I need to pass arguments to php_script_2. The equivalent href (HTTP request) would be .../make_objects.php?dt=data99&z=4
so these arguments become available in php as $_REQUEST and $_REQUEST.
What I have tried
I tried the following:
...
$command = "php /var/www/make_objects.php?dt=data99&z=4";
$priority = 0;
$pid = run_in_background($command, $priority);//kick off background process
...
but get the error: Could not open input file: /var/www/make_objects.php?dt=data99&z=4
. The *nix command parser clearly doesn't allow that.
Research on the web has failed to identify the correct approach.
My Question
How do I construct $command to call /var/www/make_objects.php
and pass named arguments dt=data99
and z=4
?
Many thanks in advance to the *nix guru(s) who understand this stuff.
Airshow