[TYPO3] clear cache from cron script

Loek Hilgersom hilgersom at xs4all.nl
Wed Jul 18 15:55:39 CEST 2007


Hi Dimitry,

Thanks for your suggestion, I got it to work!

Here's the entire script, for whoever is interested in clearing the Typo3 cache 
from applications outside of Typo3. The way it's set up now the script should be 
located in typo3conf/ext/your_extension/scriptname.php, otherwise you'll have to 
adjust the path definitions on top.

Cheers,
Loek


<?php

define("PATH_typo3conf", dirname(dirname(dirname(__FILE__)))."/");
define("PATH_site", dirname(PATH_typo3conf)."/");
define("PATH_typo3", PATH_site."typo3/");       // Typo-configuraton path
define("PATH_t3lib", PATH_site."t3lib/");
define('TYPO3_MODE','BE');
ini_set('error_reporting', E_ALL ^ E_NOTICE);

require_once (PATH_t3lib.'class.t3lib_div.php');
require_once (PATH_t3lib.'class.t3lib_extmgm.php');
require_once (PATH_t3lib.'class.t3lib_tcemain.php');

require_once(PATH_t3lib.'config_default.php');

if (!defined ("TYPO3_db")) die ("The configuration file was not included.");
require_once(PATH_t3lib.'class.t3lib_db.php');          // The database library
$TYPO3_DB = t3lib_div::makeInstance('t3lib_db');
$TYPO3_DB->sql_pconnect (TYPO3_db_host, TYPO3_db_username, TYPO3_db_password);
$TYPO3_DB->sql_select_db (TYPO3_db);

$tce = t3lib_div::makeInstance('t3lib_TCEmain');
$tce->clear_cacheCmd(40);  // ID of the page for which to clear the cache

?>


API 4.1 reference for other options of clear_cacheCmd():
http://doc-typo3.ameos.com/4.1.0/classt3lib__TCEmain.html#c500d6626afa7bb0f6a7775e842cb70a


Dmitry Dulepov wrote:
> Loek Hilgersom wrote:
>> I need to run a cron job which will update data for an extension in 
>> Typo3. After updating the data I need to clear the FE-cache for that 
>> specific page. How do I do that properly?
>>
>> Is it a matter of just emptying some records in cache_pages
>> (DELETE FROM cache_pages WHERE id=x)
> 
> No. This will not clear cache properly, it will leave data in other 
> tables and sometimes in file system.
> 
>> or is there a more appropriate way to achieve this?
> 
> You need to look to t3lib/class.t3lib_tcemain.php and its clear_cacheCmd 
> function. Also search for "makeInstance('t3lib_TCEmain') to see how to 
> instantiate tcemain properly.
> 


More information about the TYPO3-english mailing list