30.06.2016 Views

Magento Site Performance Optimization

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 4<br />

#! /bin/sh<br />

# /etc/init.d/syncache.sh<br />

#<br />

echo "Synching <strong>Magento</strong> Cache to Hard drive"<br />

echo [`date +"%Y-%m-%d %H:%M"`] <strong>Magento</strong> Cache Synched to Disk >> /<br />

var/log/magento_ram_cache.log<br />

rsync -av --delete --recursive --force /var/www/YOUR_DOMAIN.<br />

COM/var/cache/ /var/www/YOUR_DOMAIN.<br />

COM/var/cache-backup/<br />

exit 0<br />

The previous script will, indeed, if launched, synchronize the file between the<br />

RAM mounted folder and the backup folder. It will echo Synching <strong>Magento</strong><br />

Cache to Hard drive every time it's launched. Also, this script will write<br />

the following line in a file named /var/log/magento_ram_cache.log:<br />

Year month day Hours minutes <strong>Magento</strong> Cache Synched to Disk<br />

4. However, it's not yet automatized. In order to do it, you have to add an entry<br />

in the cron job table to our system. In Linux systems, the cron table is used to<br />

schedule commands that will be executed periodically and is used as follows:<br />

* * * * * user command to be executed<br />

The asterisks stand for minutes (0 to 59), hours (0 to 23), days of the month (1<br />

to 31), days of the week (0 to 7, both 0 and 7 are for Sunday).<br />

5. To edit the cron table, use the following command:<br />

$ crontab –e<br />

Add the following line to run the script every 10 minutes:<br />

* /10 * * * * root /etc/init.d/syncache<br />

From now on, the cache files belonging to the cache mechanisms built into <strong>Magento</strong><br />

will be stored in an automatically mounted in-RAM directory. Moreover, the content<br />

of this directory will be synchronized with the hard drive every 10 minutes in order<br />

to avoid important data losses.<br />

[ 57 ]<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!