Standalone Magento Full Page Cache Shell Script for Cronjob

With full page cache auto generation turned on, we found the cron job is taking too long to run on a large site and is holding up all other cron jobs, so we have removed this cron job (enterprise_page_cache_crawler) from Magento cron and have created a separate cron job specifically for the cache crawler.

The PHP file to do the full page cache should be run from the shell and is:

require '../app/Mage.php';
Mage::app('admin')->setUseSessionInUrl(false);
Mage::getModel('enterprise_pagecache/crawler')->crawl();

The shell script to run in the cron is:

!/bin/sh
# location of the php binary
if [ ! "$1" = "" ] ; then
CRONSCRIPT=$1
else
CRONSCRIPT=cachecrawlercron.php
fi

PHP_BIN=`which php`

# absolute path to magento installation
INSTALLDIR=`echo $0 | sed 's/cachecrawlercron.sh//g'`

#       prepend the intallation path if not given an absolute path
if [ "$INSTALLDIR" != "" -a "`expr index $CRONSCRIPT /`" != "1" ];then
    if ! ps auxwww | grep "$INSTALLDIR""$CRONSCRIPT" | grep -v grep 1>/dev/null 2>/dev/null ; then
        $PHP_BIN "$INSTALLDIR""$CRONSCRIPT" &
    fi
else
    if  ! ps auxwww | grep " $CRONSCRIPT" | grep -v grep | grep -v cron.sh 1>/dev/null 2>/dev/null ; then
        $PHP_BIN $CRONSCRIPT &
    fi
fi

Finally the command to put the shell script in the cron is:

0 1 * * 0,2,4 /bin/sh /path/to/magento/home/directory/shell/cachecrawlercron.sh
One comment on “Standalone Magento Full Page Cache Shell Script for Cronjob
  1. alex says:

    Thanks for sharing, I am using cloudways full page cache extension for my Magento store, which is totally free and keeps my store faster.

Leave a Reply

Your email address will not be published. Required fields are marked *

*