问题
I have the following in a PHP document I'm calling from a cron job.
if (is_file($docRoot . $row['cron_action_script_path'])) {
system("php " . $docRoot . $row['cron_action_script_path'] . $row['params']);
}
However, I'm getting the error Could not open input file: /path/to/file.php?params=1
But I am getting past the if statement is_file('/path/to/file.php')
So it looks like there's a problem with including get variables on SHH calls to PHP document.
Is there anyway around this? I need to be able to dynamically call my params in some fashion.
回答1:
if (is_file($docRoot . $row['cron_action_script_path'])) {
$_GET['params'] = $row['params'];
include $docRoot . $row['cron_action_script_path'];
}
回答2:
You are making a call to the php CLI and attempting to use QUERY STRING
data, which is webserver specific. You will either need to revamp the script to accept parameters or call it using a program such as lynx
, curl
or wget
So make the system call something like:
system("wget http://yourdomain.com/path/to/file.php?params=1 > /dev/null");
Which should then execute that script using webserver which would allow the QUERY STRING
.
EDIT:
Tailored to using your variables: (Note there may need to be a slash after the .com)
system("wget http://yourdomain.com" . $row['cron_action_script_path'] . $row['params'] . " > /dev/null");
回答3:
Try is_readable
instead of is_file
. A file can exist without being readable by your current user.
Passing params like that isn't going to work, though. You can't do $_GET
variables on the commandline. Take a look at how PHP expects and handles commandline arguments.
来源:https://stackoverflow.com/questions/7475344/call-php-document-with-ssh-includes-get-variable