[TYPO3-core] RFC: cli_dispatch.phpsh

Martin Kutschker Martin.Kutschker at n0spam-blackbox.net
Wed Nov 29 11:34:02 CET 2006


Ernesto Baschny [cron IT] schrieb:
> This is a SVN patch request
> 
> Type: Bugfix
> 
> Description:
> 
> Kasper added the nice "cli_dispatch.phpsh" script to TYPO3 core. I was
> trying to use it to call some CLI's, but it failed with:
> 
> ERROR: /home/ernst/typo3cvs.cron.stgt.vpn/typo3/ was not a file. Maybe your
> environment does not support running this script with a relative path? Try
> to run the script with its absolute path and you should be fine.
> 
> Neither $_ENV['_'] nor $_SERVER['_'] is set on my server ("standard"
> SuSE Linux with PHP 4.3.8).

Fine with me.

There is another good reason for argv and not _. Example of shell.php which 
only echoes $_SERVER['argv'][0] and $_SERVER['_']:

# shell.php
argv: shell.php
_: shell.php

# php shell.php
argv: shell.php
_: /usr/bin/php

_ will contain the path to the interpeter, when the PHP script is called 
indirectly.

> The attached patch just changes the method of finding out the current
> path to using $_SERVER['argv'][0], which should always be set when
> calling a PHP script from CLI.

There is another error:

	// First argument is a key that
define('TYPO3_cliKey', $_SERVER["argv"][0]);

Index 0 contains (as your patch suggests) the program not the argument.

There is a potential problem with the guessing of the path via 
$_SERVER['PWD']. The working directory has nothing to do with location of 
the script. Furthermore the "is absolute path" check is not portable (will 
break on Windows).

A better way is to use realpath(). The caveat here is that returns the 
absolute path and resolves symlinks. But it is probably better than PWD, 
which can be anything.

Masi

PS: Does it work at all? It doesn't seem to set TYPO3_cliInclude and does 
not refer to $TYPO3_CONF_VARS['SC_OPTIONS']['GLOBAL']['cliKeys'] except in 
a comment.


More information about the TYPO3-team-core mailing list