[TYPO3-dev] HowTo: Running a cronscript using TYPO3 with CLI
Ernesto Baschny [cron IT]
ernst at cron-it.de
Thu Jan 3 17:08:26 CET 2008
Steffen Kamper wrote: on 03.01.2008 16:54:
>>>> 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.
>>> Please don't do it this way. Use the script typo3/cli_dispatch.php to
>>> launch your script.
>> "Inside TYPO3" describes the old-school way Steffen describes. It looks
>> pretty "complete" to me:
>>
>> http://typo3.org/documentation/document-library/core-documentation/doc_core_inside/4.1.0/view/3/5/#id3561750
>>
>> but unfortunately this is "old-school". As Masi said, using
>> typo3/cli_dispatch.php is the "way to go". Someone has to change that
>> section in "Inside TYPO3" to reflect that, as I don't see cli_dispatch
>> documented anywhere.
>>
>> You can follow the examples in the sysext/lowlevel. Basically this means:
>>
>> => BE-user "_CLI_lowlevel". This user has to have the rights you need
>> the script to have. So if the script performs high-level TCEmain
>> operations, it needs to have access to the fields you want to change!
>>
>> => ext_localconf.php:
>> $TYPO3_CONF_VARS['SC_OPTIONS']['GLOBAL']['cliKeys']['lowlevel_cleaner']
>> = array('EXT:lowlevel/dbint/cli/cleaner_cli.php','_CLI_lowlevel');
>>
>> => lowlevel/dbint/cli/cleaner_cli.php:
>> Straight PHP-code where you already have the TYPO3-framework loaded (no
>> more BACK_PATH stuff etc). Just "do your stuff" here.
>>
>>
>> Then call your stuff with:
>> $ php <Root>/typo3/cli_dispatch.phpsh lowlevel_cleaner
> Hi Ernesto,
>
> i didn't found this document, thx for the link.
> I don't see a BACK_PATH problem, it's same stuff as in every BE-module -
> defined one time and could be used.
The same problem you have with BE-modules will arise in CLI-modules. See
thread "SymLinked typo3/ext" about some trouble this hardcoded path
might produce.
> I didn't used it, as there is also the way with the constants or
> EXT:xxx-syntax.
You used it here:
// Include init file:
require(dirname(PATH_thisScript).'/'.$BACK_PATH.'init.php');
which is the most important call for loading the TYPO3-framework.
> Ok, switching to cli_dispatch is no problem, only missing documentation. But
> all is done in lowlevel, so these parts could be copied.
lowlevel is just one specific CLI application, your own don't have
anything to do with that. I don't see how they are related, they only
use the same API.
> So little additional question, how can I access commandline parameters? e.g.
> i want to start my script this way
> /abspath/typo3/cli_dispatch.phpsh mysscript -f 100
You pass $_SERVER['argv'] to your main() method of your class and it can
handle the command line the way it wishes. AFAIK we don't have any
getopt()-like functionality in TYPO3-core, so you have to do it your own
way.
Cheers,
Ernesto
More information about the TYPO3-dev
mailing list