0

I need to run a PHP script once at a specific time. I'm doing it by:

shell_exec('echo /usr/local/bin/php /home/xxx/public_html/yyy.php param1 | /usr/bin/at now + 1 minutes');

yyy.php takes param1 from $_SERVER['argv'][1] and does its thing based on the value. I've tested yyy.php and the script works as it should. The problem I'm running into is I can't seem to get the at command to properly execute the PHP script. I've tried different variants, such as:

shell_exec('/usr/local/bin/php /home/xxx/public_html/yyy.php param1 | /usr/bin/at now + 1 minutes');

shell_exec('echo "/usr/local/bin/php /home/xxx/public_html/yyy.php param1" | /usr/bin/at now + 1 minutes');

Nothing works. I've double checked and made sure the at command is being queued by calling atq in terminal -- the job shows up. I think the issue is with how I've setup the at command. Any ideas? Thanks!

user4951834
  • 681
  • 2
  • 11
  • 26
  • tried to run this from the command line? –  Jul 10 '15 at 04:08
  • @Dagon Yes I have -- the at command is being queued (I checked with atq) but the PHP script is not executing like it should – user4951834 Jul 10 '15 at 06:59
  • @Dagon If I do `cd /home/xxx && echo "/usr/local/bin/php /home/xxx/public_html/yyy.php param1" | /usr/bin/at now + 1 minutes` then it works from command line. However, I tried `shell_exec('cd /home/xxx && echo "/usr/local/bin/php /home/xxx/public_html/yyy.php param1" | /usr/bin/at now + 1 minutes');` and it still doesn't work. – user4951834 Jul 10 '15 at 08:50

1 Answers1

1

After much work, this is what finally worked for me:

a) CHMOD yyy.php to 755

b) Use shell_exec('cd /home/xxx && echo "/usr/local/bin/php /home/xxx/public_html/yyy.php param1" | /usr/bin/at now + 1 minutes'); in PHP script

user4951834
  • 681
  • 2
  • 11
  • 26