1

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!

Community
  • 1
  • 1
scott
  • 11
  • 1
  • 4
  • Correct me if I'm wrong (it would be cool) but I don't think you can just append a query string to the filename and call it with `php filename?querstring`. Is there actually a file named "batch_email_send_u2u.php?dealer=7" ? – Dan Dec 22 '15 at 00:13
  • Oh interesting - that could be part of the problem I suppose. The file is batch_email_send_u2u.php and the query string is dealer=7. Of course I can add the querystring when I call it in the browser, but why can't it be added when calling from the command line? If that is indeed true, any suggestions on how I can pass parameters in that would be picked up by $_GET? – scott Dec 23 '15 at 03:22
  • You could set `$_GET` before calling the script. `shell_exec("php $_GET['dealer'] = 7; $path$base_url > output_test.txt 2>&1 &");` , but there is probably a better way. – Dan Dec 23 '15 at 03:25

1 Answers1

0

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.

Community
  • 1
  • 1
scott
  • 11
  • 1
  • 4