Magento: Clear the cache with PHP script.

In: PHP

15 Jul 2009

It always take time to get rid of the Magento cache. However cache is needed to execute the request faster. One way of clearing the cache is delete all the directories inside the /var/cache directory. Doing that manually it will take some time if you are connected to the FTP server.
The easiest way of clearing the cache in Magento is here.

<?php

ini_set('max_execution_time', 3600);
ini_set("memory_limit","256M");

$script = "rm -rf var/cache/*";
// replace 'syste m' with 'system' in this line
$results = syste m($script,$retval);
echo " Cache cleared, RETURN VALUE: $retval\n";

?>

Name the file clearcache.php. Put it in the root directory of the Magento setup & execute in the browser.

4 Responses to Magento: Clear the cache with PHP script.

Avatar

mtness

November 11th, 2009 at 4:14 pm

ah – what a timesaver.

Another beautiful scrpt of yours, thank you so much!

Kind regards, mtness

Avatar

Jordan

December 17th, 2009 at 12:05 am

This worked like a charm. Thanks very much for posting.

Avatar

manish patel

February 8th, 2010 at 1:24 pm

Hello Jignesh patel,

Your script works fine. thank you so much.

Regards,
manish patel

Avatar

Lisa

February 16th, 2010 at 1:15 am

Thanks so much! Worked perfectly!

Comment Form

About this blog

Hello, Welcome to the Magento Coder.
I am Jignesh Patel, a Web Developer.

About Jignesh