2015-07-10 03:59
浏览 51


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!

图片转代码服务由CSDN问答提供 功能建议

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

  shell_exec('echo / usr / local / bin / php /home/xxx/public_html/yyy.php param1 | / usr / bin / 现在+ 1分钟'); 

yyy.php从 $ _ SERVER ['argv'] [1] 获取param1 它基于价值的东西。 我已经测试了yyy.php,脚本可以正常工作。 我遇到的问题是我似乎无法获得 at 命令来正确执行PHP脚本。 我尝试了不同的变体,例如:

  shell_exec('/ usr / local / bin / php /home/xxx/public_html/yyy.php param1 | / usr /  bin /现在+ 1分钟'); 
shell_exec('echo“/ usr / local / bin / php /home/xxx/public_html/yyy.php param1”| / usr / bin / at now + 1 minutes'  ); 

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

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

  • dongzhuang6417 2015-07-10 09:27

    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

    解决 无用
    打赏 举报

相关推荐 更多相似问题