简体   繁体   English

如何调试似乎未运行的PHP CRON脚本?

[英]How can I debug a PHP CRON script that does not appear to be running?

I am trying to setup a CRON job using PHP, but am not having any luck so far. 我正在尝试使用PHP设置CRON作业,但到目前为止没有任何运气。

I am following this tutorial: PHP - Create a Cron Job with PHP (dead link) 我正在学习本教程: PHP-使用PHP创建Cron作业 (无效链接)

I have created the script file with the correct permissions, but the script is not being processed. 我已经使用正确的权限创建了脚本文件,但是脚本未得到处理。

Any ideas? 有任何想法吗?

Maybe your cron daemon isn't running? 也许您的cron守护程序没有运行? The daemon "crond" have to run on startup. 守护程序“ crond”必须在启动时运行。

Check this with "ps -efc |grep crond" 通过“ ps -efc | grep crond”进行检查

Little checklist: 小清单:

  1. Is your cron running -> u2ix [checked] 您的cron是否正在运行-> u2ix [已检查]
  2. Permissions to use cron [checked] 使用cron的权限[已选中]
  3. Does your script run in the shell [checked i hope] 您的脚本是否在外壳中运行[我希望选中]
  4. Run a litte script that shows you the environmet in your cron (-> env) / it is never the same as in your shell :-) 运行一个litte脚本,向您显示cron(-> env)中的环境/它与您的shell中的环境永不相同:-)
  5. after execute your php-creat-cronjob-script check with corntab -l the crontab 用corntab -l执行您的php-creat-cronjob-script检查后,crontab

-- do you get mail from your cron ? -您从您的Cron收到邮件吗?

it seems you could have any number of issues here. 看来这里可能有很多问题。

Firstly have you checked that the file runs successfully from the command line? 首先,您是否已从命令行检查文件是否成功运行?

if so another simple solution to the problem could be if you didn't set the file to be added correctly in $command so this could be pointing to a file you don't have. 如果是这样,则该问题的另一种简单解决方案是,如果您未在$ command中设置要正确添加的文件,则这可能指向您没有的文件。

Also checking that to cron file you have specified matches the directory referenced in these lines: 还要检查您指定的cron文件是否与这些行中引用的目录匹配:

    // this will reinstate your Cron job

    exec("crontab /Users/vin/Sites/site/cron/Feed_cron"); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM