如何使用at命令在特定时间运行PHP脚本?

编程入门 行业动态 更新时间:2024-10-28 14:24:03
本文介绍了如何使用at命令在特定时间运行PHP脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我需要在特定时间运行一次 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屋!

更多推荐

[db:关键词]

本文发布于:2023-05-01 00:11:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1401812.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   脚本   命令   时间   在特定

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!