[TYPO3-core] RFC: cli_dispatch.phpsh

Martin Kutschker Martin.Kutschker at n0spam-blackbox.net
Wed Nov 29 17:40:59 CET 2006


Ernesto Baschny [cron IT] schrieb:
> Ernesto Baschny [cron IT] wrote: on 29.11.2006 10:46:
> 
> 
>>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).
>>(...)
>>-$temp_PATH_thisScript = isset($_ENV['_']) ? $_ENV['_'] : $_SERVER['_'];
>>+$temp_PATH_thisScript = $_SERVER['argv'][0];
> 
> 
> I've got feedback from Kasper (please follow-up to typo3.team.core,
> Kasper). He prefers to add the checking for $_SERVER['argv'][0] instead
> of replacing what we already have there:
> 
> isset($_ENV['_']) ? $_ENV['_'] : (isset($_SERVER['_']) ? $_SERVER['_'] :
> $_SERVER['argv'][0]);
> 
> The problem with that, as Martin explained, is that it will never work
> when calling the script using the syntax:
> 
> % php -f <path>/typo3/cli_dispatch.phpsh
> 
> This is required on Windows, and some people prefer to do that also
> unter Unix.
> 
> As "$_SERVER['argv'][0]" is the documented way of accessing the
> information, I would prefer to turn it around in checking that first and
> just if it fails, continue with checking for $_ENV['_'], which I would
> call non-standard.
> 
> Votes?

Check $_SERVER['argv'][0] first and then do a fallback to $_ENV['_'] and 
$_SERVER['_'].

> Martin Kutschker wrote on 29.11.2006 11:34:
> 
> 
>>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.
> 
> 
> True, as this is not used anywhere in init.php, I would also vote (+1)
> for dropping this define, as it probably comes from some original
> CLI-script which was transformed into the "dispatcher".
> 
> Votes about this?

I didn't check the context, but the comment on top of the file says the 
"key" is used to include the file. I don't see where this is done, but 
whatever is done, should be done synced (ie changign code and comments).

But if the define is really not needed then drop it.

>>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).

> If we called script with relative adressing, the current path has an
> important role into finding out the "full path" of the script. Just
> append one to the other. The current setup only works under Unix,
> because of this condition:
> 
> if ($temp_PATH_thisScript{0}!='/')      {
> 
> An absolute path on Windows won't start with "/". While this fallback of
> finding the "real path" works under Unix it will break any call to it
> under Windows. But I have no time currently to do more intensive
> researches on that currently, and would be happy if this first patch
> could make it through.

Ok, but please add a comment a la "// works only on Unix".

>>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.
> 
> Using realpath has the same problem as using __FILE__ as you noted
> before, because you will get the path of the typo3_src directory and not
> the current real installation directory, where "typo3/" might just be a
> symlink to the sources.

Ouch, I forgot to check this, but it seems logical.

>>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.
> 
> It does work, because init.php will set TYPO3_cliInclude if being called
> from this dispatcher script. When init.php finishes, the dispatcher will
> then just include the desired CLI-script.

Aha. And you say, it does not use the cliKey for this.

Masi


More information about the TYPO3-team-core mailing list