如何使用at命令在特定时间运行PHP脚本? [英] How to run PHP script at a certain time using at command?

查看:27
本文介绍了如何使用at命令在特定时间运行PHP脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在特定时间运行一次 PHP 脚本.我是这样做的:

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 从 $_SERVER['argv'][1] 获取 param1 并根据该值执行其操作.我已经测试过 yyy.php 并且脚本可以正常工作.我遇到的问题是我似乎无法获得 at 命令来正确执行 PHP 脚本.我尝试了不同的变体,例如:

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');

没有任何效果.我已经仔细检查并确保 at 命令正在通过在终端中调用 atq 排队 - 作业显示出来.我认为问题在于我如何设置 at 命令.有任何想法吗?谢谢!

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 到 755

a) CHMOD yyy.php to 755

b) 使用 shell_exec('cd/home/xxx && echo "/usr/local/bin/php/home/xxx/public_html/yyy.php param1" |/usr/bin/atnow + 1 分钟'); 在 PHP 脚本中

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

这篇关于如何使用at命令在特定时间运行PHP脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆