简体   繁体   中英

How to run PHP script at a certain time using at command?

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

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