doudui6756
2013-09-09 16:06
浏览 110
已采纳

设置Crontab以在CentOS中执行PHP脚本

I have searched hell and high water for a solution to a problem I'm having in CentOS. I'm trying to set up a cron job that executes a PHP script. I was able to get this working using wget, but now that we are going into production, I need to find a way to do this whilst being more secure, as the cron job itself works with sensitive data.

The error that I'm getting is: -bash: php: command not found.

Now I've looked around and I've seen people having the same problem, but nothing has been able to help me get this working.

For reference, here is what the working crontab looked like using the wget command.

* * * * * wget http://www.domain.com/cron_script.php

This is working fine, but I need to translate this into executing via PHP, rather than making an HTTP request to get the job done.

Let me know if I left anything out.

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

我搜索了地狱和高水位,以解决我在CentOS遇到的问题。 我正在尝试设置执行PHP脚本的cron作业。 我能够使用 wget 来实现这一点,但是现在我们正在投入生产,我需要找到一种方法来实现这一点,同时更安全,因为cron作业本身可以处理敏感数据。

我得到的错误是: -bash:php:command not found

现在我' 环顾四周,我看到有人遇到同样的问题,但没有任何东西可以帮我搞定。

作为参考,以下是使用crontab的工作原理 wget 命令。

* * * * * wget http://www.domain.com/cron_script.php

这工作正常,但我需要将其转换为执行 通过PHP,而不是发出HTTP请求来完成工作。

如果我遗漏了任何东西,请告诉我。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doupin5667 2013-09-09 16:10
    已采纳

    Cron doesn't have it's PATH set. The easiest thing is to change the php command to the full path of the php binary.

    /usr/bin/php /path/to/yourscript.php

    I'm fairly certain that's the path in CentOS but you can know for sure by doing which php on the command line and it will tell you.

    点赞 打赏 评论

相关推荐 更多相似问题