Does a PHP script executed with exec() from a web-accessible endpoint have access to $_POST?
I have a web service endpoint that needs to invoke another developer's CLI PHP script as part of its run. Pseudocode like so:
function startCLI($input, $output){
$cmd = escapeshellarg('php bin/startcli.php $input $output');
exec($cmd, $output, $ret);
if ($output){
print_r($output[0]);
}
}
Now, you might be asking: why not 开发者_如何学Cpass the $_POST['var']
to the clistart.php
script?
Well, you get what you pay for when you get your legacy code from overseas, sometimes, and the time it would take me to take apart their system and put it back together is greater than the time I have to implement the whole solution.
So let's just stipulate that I cannot add new variables to the clistart.php
script, and take it from there. Hell, take it as an academic exercise. Does a CLI script executed from a web-requested PHP script have access to $_GET or $_POST for its run?
UPDATE: I've tried both adding keys to $_ENV and getenv()
and putenv()
, but the result is the same - I can update the environment for the current script and the child script that it's executing to QUEUE the job, but since the jobs are then being run by a persistent process that has its own $_ENV context, there doesn't appear to be a way to pass that variable along to the persistent process' context.
I'll either have to resort to the database or a file touch, unless someone has another idea.
$_GET and $_POST are part of the scripts web request context and won't be available in CLI, it will have it's own context populated.
Not without exporting the array contents as environment variables - via putenv.
But why is a CLI script looking into HTTP variables anyway? A CLI-only script wouldn't even look at them.
Or by CLI do you mean it's designed to run as a CGI script?
精彩评论