[Tickets #3791] NEW: Horde_CLI::runningFromCLI() can erroneously return 'false' after Horde_CLI::init() is called

bugs@bugs.horde.org bugs at bugs.horde.org
Tue Apr 18 21:41:24 PDT 2006


DO NOT REPLY TO THIS MESSAGE. THIS EMAIL ADDRESS IS NOT MONITORED.

Ticket URL: http://bugs.horde.org/ticket/?id=3791
-----------------------------------------------------------------------
 Ticket             | 3791
 Created By         | dorm at dorm.org
 Summary            | Horde_CLI::runningFromCLI() can erroneously return 'false' after Horde_CLI::init() is called
 Queue              | Horde Framework Packages
 Version            | FRAMEWORK_3
 State              | Unconfirmed
 Priority           | 1. Low
 Type               | Bug
 Owners             | 
-----------------------------------------------------------------------


dorm at dorm.org (2006-04-18 21:41) wrote:

The Horde_CLI::runningFromCLI() function can erroneously return 'false' when
it should return 'true' after a call to Horde_CLI::init().  This is because
Horde_CLI::init() sets $_SERVER['SERVER_NAME'] to '127.0.0.1'.  
Horde_CLI::runningFromCLI() checks for an empty($_SERVER['SERVER_NAME']) to
confirm that we are running from CLI if php_sapi_name() returns 'cgi'. 
Since $_SERVER['SERVER_NAME'] has been set to '127.0.0.1' by a previous call
to Horde_CLI::init(), Horde_CLI::runningFromCLI() returns false.

This does not seem to be a major issue, except if the static method
Horde_CLI::init() is called before instantiating the Horde_CLI class, then
the class constructor incorrectly sets values for $this->_newline,
$this->_indent, etc.  You get HTML output instead of vt100/xterm/etc. output
from the command line.

FYI I discovered this while working with the ansel/scripts/ansel.php CLI
script.

The following patch adds a check for $_SERVER['SERVER_NAME'] == '127.0.0.1'
to Horde_CLI::runningFromCLI(), and is working well for me:

@@ -336,7 +336,7 @@
         if ($sapi == 'cli') {
             return true;
         } else {
-            return $sapi == 'cgi' && empty($_SERVER['SERVER_NAME']);
+            return $sapi == 'cgi' && (empty($_SERVER['SERVER_NAME']) ||
$_SERVER['SERVER_NAME'] == '127.0.0.1');
         }
     }





More information about the bugs mailing list