1

Trying to run cron tasks using 0 */1 * * * root curl -s http://site.name/cron.php?cron_key=secret_key >> /var/log/site-cron.log 2>&1 or 0 */1 * * * root wget -O - -q -t 1 http://site.name/cron.php?cron_key=secretkey >> /var/log/site-cron.log 2>&1 doesn't work.

Using 0 */1 * * * root curl -s http://site.name/cron.php?cron_key=secret_key >> /var/log/site-cron.log 2>&1 and 2 */1 * * * root curl -s http://site.name/cron.php?cron_key=secret_key >> /var/log/site-cron.log 2>&1, the second attempt works.

Access log shows both calls, but dblog shows only the second attempt. There are no errors in nginx log, cron log, php-fpm log.

How do I fix this?

UPD: thanks @zhilevan. I was able to debug cron scripts with his help. This way drush --root=/usr/share/nginx/demo --quiet cron displays errors in cron scripts.

3
  • does your site hosted on the same server your crontab created?
    – Yuseferi
    Mar 28, 2017 at 5:53
  • @zhilevan, yes, same server
    – stan
    Mar 28, 2017 at 7:30
  • did you try my latest solutions?
    – Yuseferi
    Mar 28, 2017 at 19:58

2 Answers 2

0

If your source code and crontab on the same server I suggest try to run internally by PHP, Try something like

0 */1 * * * root  /usr/bin/php /home/sites/example.com/public_html/cron.php
  • /usr/bin/php = your php path
  • /home/sites/example.com/public_html/ = your site source code path

For getting more information read Configuring cron jobs using the cron command.

Update: Solution 2 : create bash script

touch ~/scripts/cron-php.sh
chmod 700 ~/scripts/cron-php.sh
vi ~/scripts/cron-php.sh

filled it with

#!/bin/bash
root_path=/usr/share/nginx/demo/
parse=/usr/bin/php

# PHP parser options
#
# Defaulting to not report notices.
parse_options="-d error_reporting=2037"

# Verbosity
#
# Default to only report errors.
verbose=false


cd $root_path

if [ -e "cron.php" ]
then
    $parse $parse_options cron.php
    if [ "$?" -ne "0" ]
    then
         echo "cron.php not parsed."
    else
         if $verbose
         then
             echo "cron.php has successfully been parsed."
         fi
    fi
else
    echo "cron.php not found."
    exit
fi

exit

and then the crontab itself:

$crontab -e
*/1 * * * * ~/scripts/cron-php.sh

Third Solution is based on Drush

According to Drush Doc

0 */1 * * * /usr/bin/env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin COLUMNS=72 /usr/local/bin/drush --root=/usr/share/nginx/demo --uri=your.drupalsite.org --quiet cron
13
  • When I changed cron call to */1 * * * * root /usr/bin/php /usr/share/nginx/demo/cron.php >> /var/log/demo-cron.log 2>&1, I've got an error in cron.php Fatal error: Call to undefined function drupal_bootstrap() in /usr/share/nginx/demo/cron.php on line 14 because getcwd() function returns incorrect path /root instead /usr/share/nginx/demo
    – stan
    Mar 28, 2017 at 9:34
  • @stan do you have drush on your server?
    – Yuseferi
    Mar 28, 2017 at 9:39
  • yes. version 8.0.1
    – stan
    Mar 28, 2017 at 9:46
  • @stan try the second solution while I'm going to provide another solution base on drush.drush solution is provided for you too.
    – Yuseferi
    Mar 28, 2017 at 9:50
  • both doesn't work. third solution doesn't run drupal cron like a simple curl or wget request. second solution can't run drupal cron, error "invalid cron key"
    – stan
    Mar 29, 2017 at 6:47
0

Running cron tasks before clear all your cache. During development it is necessary to clear the cache very frequently. Clearing caches is relatively harmless. Sites might slow down for a bit afterwards while the cache fills back up.

2
  • Thanks, I'll try. How is the cache influences on cron tasks?
    – stan
    Mar 28, 2017 at 7:35
  • Yes, running cron.php still clear cache, as running the cron will call system_cron which calls "cache_clear_all" method.
    – anbarasan
    Mar 28, 2017 at 8:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.