Bug #17271
closedcli_dispatch.phpsh will not run on CGI API
0%
Description
When running "typo3/cli_dispatch.phpsh crawler" in command line, I get the error message "ERROR: Not called from a command line interface (eg. a shell or scheduler)." I am of course running it from the command line, and PHP_SAPI is "cgi" (tested by inserting an echo in the script).
Tested in Typo3 4.1 and 4.1.1.
(issue imported from #M5548)
Files
Updated by Rohrle Tobias over 17 years ago
Same problem here:
cat /etc/redhat-release
Red Hat Enterprise Linux ES release 4 (Nahant Update 4)
php -v
PHP 4.3.9 (cgi) (built: Nov 2 2006 16:39:38)
Copyright (c) 1997-2004 The PHP Group
Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies
typo3 4.1.1
I have tried to relax the test with:
##
if (PHP_SAPI!='cli' && PHP_SAPI!='cgi') {
die('ERROR: Not called from a command line interface (eg. a shell or scheduler). PHP_SAPI = "' . PHP_SAPI . '".'.chr(10));
}
##
but there must be a silent error, because it does not what expected (crawler background indexing) nor raise a warning/error.
Same command works well on similar installation excepted "php -v" reports "...(cli)..."
Updated by Michael Stucki over 17 years ago
PHP_SAPI is expected to be "cli" not "cgi"!
I don't know much about the differences between the cli and cgi SAPIs. Probably it works as well, but "cli" is definitely more appropriate...
Please check if it works even with CGI...
Updated by Martin Kutschker over 17 years ago
What is the output of "php -i"? Is it plain text or HTML? For CLI it should be text, only, the CGI variant outputs HTML.
Updated by Mathias Bolt Lesniak over 17 years ago
When changing
if (PHP_SAPI!='cli')
to
if (PHP_SAPI!='cgi')
The script runs fine in command line.
Updated by Rohrle Tobias over 17 years ago
After changing the test as mentioned above the "silent" failure was due to running "cli mode" + "IPmaskList".
The "Check IP" test in the file init.php failed because t3lib_div::getIndpEnv('REMOTE_ADDR') returned the empty string...
This might be a bug.
Concerning cli / cgi, I understand that PHP_SAPI is expected to be "cli" which is the right one. But in my case the support for cgi is interesting (mostly because cli isn't available in my environment).
As explained here http://www.php.net/features.commandline, cgi and cli are quite similar excepted for:
- HTTP headers (with cgi you may add the switch '-q' to sha-bang),
- working directory (with cgi you may add the switch '-C' to sha-bang),
- error message formatting (errors that are handled by typo3),
- overridden php.ini directives
This is also about portability: hard coded path to php in sha-bang...
OK for me, thank you for your help.
Updated by Martin Kutschker over 17 years ago
The CLI version has the -r option and shows (cli) in the version string whebn called as "php -v".
Updated by Martin Kutschker over 17 years ago
If you mind to use the -C and the -q switch the CGI API may mimic the CLI API with the following code:
ini_set('html_errors',0);
ini_set('implicit_flush',1);
ini_set('max_execution_time',0);
if (!ini_get('register_argc_argv')) {
$argv = $_SERVER['argv'];
$argc = $_SERVER['argc'];
}
define(STDIN, fopen('php://stdin', 'r'));
define(STDOUT, fopen('php://stdout', 'w'));
define(STDERR, fopen('php://stderr', 'w'));
Updated by Martin Kutschker over 17 years ago
It must be checked if the scripts is run from webserver. If so, the script should terminate.
Updated by Michiel Roos over 16 years ago
Hi, what's the status of this issue?
I live in an environment where even a different php is used:
:~/html/bin> php -v
PHP 5.1.6 (cgi-fcgi) (built: Feb 12 2007 15:43:18)
Copyright (c) 1997-2006 The PHP Group
Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies
So that would make the changes read:
if (PHP_SAPI!='cli' && PHP_SAPI!='cgi' && PHP_SAPI!='cgi-fcgi') {
die('ERROR: Not called from a command line interface (eg. a shell or scheduler).'.chr(10));
}
But I'm not sure if it will pass if run from the webserver now, since that probably also runs as cgi-fcgi . . .
I cannot find a PHP_SAPI set in the phpinfo() in the install tool.
I only see this: CONST: php_sapi_name: cgi-fcgi
Updated by Steffen Gebert almost 16 years ago
I've overworked the patch and resent it to core list.
Updated by Stanislas Rolland almost 16 years ago
Committed to SVN TYPO3core trunk (revision 5016) and branch TYPO3_4-2 (revision 5015).