[TYPO3-dev] HowTo: Running a cronscript using TYPO3 with CLI

Steffen Kamper steffen at sk-typo3.de
Thu Jan 3 12:19:09 CET 2008


Hi,

i searched for detailed information how to setup a CLI cronjob, but i only 
found uncomplete infos or unanswered questions, so here comes a short 
description how to do it.

1) install extension "lowlevel" (sysextension)
2) create a BE-User _cli_cronjob (doesn't need any rights, just create)
3) in your extension create folder cli
4) in folder cli create 2 files: conf.php, cronjob.phpsh
5) edit conf.php and insert:
<?php
// DO NOT REMOVE OR CHANGE THESE 3 LINES:
define('TYPO3_MOD_PATH', '../typo3conf/ext/yourextension/cli/');
$BACK_PATH = '../../../../typo3/';
$MCONF['name'] = '_CLI_cronjob'; //use name of your BE-User
?>

6) edit cronjob.phpsh and insert:
#! /usr/bin/php -q
<?php

// *****************************************
// Standard initialization of a CLI module:
// *****************************************

 // Defining circumstances for CLI mode:
define('TYPO3_cliMode', TRUE);

 // Defining PATH_thisScript here: Must be the ABSOLUTE path of this script 
in the right context:
 // This will work as long as the script is called by it's absolute path!
define('PATH_thisScript',$_ENV['_']?$_ENV['_']:$_SERVER['_']);

 // Include configuration file:
require(dirname(PATH_thisScript).'/conf.php');

 // Include init file:
require(dirname(PATH_thisScript).'/'.$BACK_PATH.'init.php');

# HERE you run your application!

that's it. You can test the script at the console, remember to call it with 
absolute path:
/var/www/.../typo3conf/ext/yourextension/cli/cronjob.phpsh

very useful is to add output of the script to a logfile, e.g.
/var/www/.../typo3conf/ext/yourextension/cli/cronjob.phpsh >>
/var/www/.../fileadmin/logs/cronjob.log

happy CLI ;-)

vg  Steffen 






More information about the TYPO3-dev mailing list