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!
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