这是/ etc / crontab的格式:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
我建议将其复制并粘贴到crontab文件的顶部,以便始终使用该参考。RedHat系统默认以这种方式设置。
每分钟运行一次:
* * * * * username /var/www/html/a.php
要在每天的午夜运行一些东西:
0 0 * * * username /var/www/html/reset.php
你可以在命令中包含/ usr / bin / php来运行,或者你可以让php脚本直接执行:
chmod +x file.php
用shebang启动你的php文件,这样你的shell就知道要使用哪个解释器:
#!/usr/bin/php
// your code here