[英]Cron job not executing a PHP file
I recently added a cron job to execute a PHP file daily, but the database is not being updated as it should be in the PHP file. 我最近添加了一个cron作业来每天执行一个PHP文件,但是该数据库没有更新,因为它应该在PHP文件中。 I'm assuming this is because the cron job is not running. 我假设这是因为cron作业未运行。
Here is what I put for the cronjob : 这是我为cronjob所做的:
@daily /etc/cron.php (located by executing crontab -l)
-- php file --
$db = new PDO("dsn", "username", "password");
$db->exec("UPDATE subscriptions SET exp_date = exp_date - 1 WHERE payment_status = 'Completed'");
The field exp_date is set to 32 whenever a user makes a purchase, but it's not being subtracted by 1 via the cronjob I have in place. 每当用户进行购买时,exp_date字段就会设置为32,但不会通过我已有的cronjob减去1。
Any help would be appreciated. 任何帮助,将不胜感激。
use crontab -e
and try with following code. 使用crontab -e
并尝试以下代码。
0 0 * * * <path>/php /etc/cron.php
This will run in everyday 00:00, and you should give the proper path to php (sample : /usr/bin/php5
) 这将在每天的00:00运行,并且您应提供php的正确路径(示例: /usr/bin/php5
)
Note : Assume that your file is running well in CLI. 注意:假设您的文件在CLI中运行良好。
If not tr with following permission and try again. 如果没有tr,请征得以下许可,然后重试。
chmod a+x /etc/cron.php
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.