简体   繁体   中英

getting Could not open input file when trying to call php script from shell_exec

I am trying to build a small custom task scheduler. Basically the idea is I have cron run my process script, which looks in the database and finds any scheduled tasks that are ready to run, and runs them. So I think the best way to do this would be to try to launch the tasks "in the background" by way of shell_exec and using > /dev/null , which I understand makes it so the initial script (the process script) doesn't wait for the task scripts to complete.
So first, if there is a better way to achieve this, I'm open to suggestions. Though note I am on php 5.3 so there may be some options in 5.4 and up that I don't have access to :(

However here's the question at hand: I am testing on WAMP on my windows machine and I am trying to make a call that looks like this:

shell_exec("php $path$base_url$querystring > output_test.txt 2>&1 &");

$path is the full windows path to the script

$base_url is the base url of the script I am calling

$querystring is of course the query string being passed to the task script

I am also outputting to output_test.txt which creates such file in same directory, where I get the following error:

Could not open input file:

C:\\xampp\\htdocs\\email\\batch_email_send_u2u.php?dealer=7

Yes I realize the path references an xampp installation, but that is not the issue - all the wamp files are executing from there and everything else has worked like this for years - it was just set up this way to support a legacy setup.

It seems to me shell_exec is locating and running php, it's just that it can't open the referenced script. Can't figure out why.

Also I need to eventually get this working on a real linux server so any advice on how to make that happen would be greatly appreciated!

Found a solution! Special thanks to dan08 for getting me set on the right path. Ultimately I found the answer in this thread: Pass variable to php script running from command line

I ended up using the argv[] array as described in that post and with a little tweak to the script I'm calling it works like a champ now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM