Project

General

Profile

Actions

Bug #17271

closed

cli_dispatch.phpsh will not run on CGI API

Added by Mathias Bolt Lesniak over 17 years ago. Updated about 6 years ago.

Status:
Closed
Priority:
Should have
Category:
-
Target version:
-
Start date:
2007-05-02
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
4.1
PHP Version:
4.3
Tags:
Complexity:
Is Regression:
Sprint Focus:

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

cli_dispatch.phpsh.patch (1010 Bytes) cli_dispatch.phpsh.patch Administrator Admin, 2007-05-03 13:15
init.php.patch (993 Bytes) init.php.patch Administrator Admin, 2007-05-03 13:15
5548_cli_dispatch.phpsh_v2.patch (851 Bytes) 5548_cli_dispatch.phpsh_v2.patch Administrator Admin, 2009-01-20 12:13
5548_cli_dispatch.phpsh_v3.patch (1.63 KB) 5548_cli_dispatch.phpsh_v3.patch Administrator Admin, 2009-01-25 17:10

Related issues 1 (0 open1 closed)

Has duplicate TYPO3 Core - Bug #19147: getFileAbsFileName returns false for EXT:lowlevel/dbint/cli/cleaner_cli.php [PHP_SAPI: cgi-fcgi]ClosedChristian Kuhn2008-07-24

Actions
Actions #1

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

Actions #2

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

Actions #3

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.

Actions #4

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.

Actions #5

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.

Actions #6

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

Actions #7

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'));

Actions #8

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.

Actions #9

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

Actions #10

Updated by Steffen Gebert almost 16 years ago

I've overworked the patch and resent it to core list.

Actions #11

Updated by Stanislas Rolland almost 16 years ago

Committed to SVN TYPO3core trunk (revision 5016) and branch TYPO3_4-2 (revision 5015).

Actions #12

Updated by Benni Mack about 6 years ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF