user2101411
user2101411

Reputation: 1202

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. I'm assuming this is because the cron job is not running.

Here is what I put for the 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.

Any help would be appreciated.

Upvotes: 0

Views: 1269

Answers (1)

Janith Chinthana
Janith Chinthana

Reputation: 3844

use crontab -e and try with following code.

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)

Note : Assume that your file is running well in CLI.

If not tr with following permission and try again.

chmod a+x /etc/cron.php

Upvotes: 1

Related Questions