[Typo3-dev] CLI API proposal

Rainer Kuhn kuhn at punkt.de
Wed Dec 1 11:39:05 CET 2004


Hi all,

in the last days I wrote some command line interface scripts using the CLI 
API of TYPO3 3.7.0 as described in "Inside TYPO3" 
(http://typo3.org/documentation/document-library/doc_core_inside/Initialize_TYPO3_bac/). 
Yesterday I transferred them to our production server running on FreeBSD and 
experienced problems with the script path using the suggested standard 
initialization of a CLI module.

As described in chapter "Tricky script path" in the above mentioned doc, "it 
seems that the path of the script is available as the variable 
$HTTP_ENV_VARS['_'] in most cases". I think this is right for Linux system 
(as $HTTP_ENV_VARS['_'] is supported apparently by bash and /bin/sh is 
actually a bash at Linux), but not for some other UNIX systems like FreeBSD.

The suggested workaround for script path problems is: "If for some reason 
the environment where the script is run does not offer this value in 
$HTTP_ENV_VARS['_'] you will have to find it elsewhere and manuall insert 
it. There seems to be no general solution for this problem."

As I thought manually inserting/hardcoding the path is not a good and 
flexible way, I looked for another solution and found the following:

http://www.php.net/manual/en/features.commandline.php
<cit>
"There are certain php.ini directives which are overridden by the CLI SAPI 
because they do not make sense in shell environments: [...]
DIRECTIVE: register_argc_argv
CLI SAPI default value: TRUE
COMMENT: Because this setting is TRUE you will always have access to argc 
(number of arguments passed to the application) and argv (array of the 
actual arguments) in the CLI SAPI.
As of PHP 4.3.0, the PHP variables $argc and $argv are registered and filled 
in with the appropriate values when using the CLI SAPI. Prior to this 
version, the creation of these variables behaved as they do in CGI and 
MODULE versions which requires the PHP directive register_globals to be on. 
Regardless of version or register_globals setting, you can always go through 
either $_SERVER or $HTTP_SERVER_VARS. Example: $_SERVER['argv']"
</cit>

In order to the current TYPO3 guidelines the command line script must always 
be executed by its absolute path, so using argv could be an alternative. So 
I tried the initialization of my CLI module using

define(PATH_thisScript, $_SERVER['argv'][0]);

instead of the suggested

define(PATH_thisScript, $HTTP_ENV_VARS['_']);

and this worked fine for me with different shells. Maybe this could be a 
general solution for the script path problem (can somebody try this on 
different systems -e.g. Windows- to check if it works in other environments)?

Comments appreciated...

Cheers,
Rainer




More information about the TYPO3-dev mailing list