6.0.0-beta1
7/22/25

[#3791] Horde_CLI::runningFromCLI() can erroneously return 'false' after Horde_CLI::init() is called
Summary Horde_CLI::runningFromCLI() can erroneously return 'false' after Horde_CLI::init() is called
Queue Horde Framework Packages
Queue Version FRAMEWORK_3
Type Bug
State Resolved
Priority 1. Low
Owners
Requester dorm (at) dorm (dot) org
Created 04/19/2006 (7034 days ago)
Due
Updated 04/19/2006 (7034 days ago)
Assigned
Resolved 04/19/2006 (7034 days ago)
Github Issue Link
Github Pull Request
Milestone
Patch No

History
04/19/2006 03:49:49 PM dorm (at) dorm (dot) org Comment #5 Reply to this comment
Works like a charm, thank you.


04/19/2006 03:28:40 PM Chuck Hagenbuch Comment #4 Reply to this comment
I find a valid and very smart solution, if I may say so.
You may. Nice. ;)
04/19/2006 07:08:53 AM Jan Schneider Comment #3
State ⇒ Resolved
Reply to this comment
I find a valid and very smart solution, if I may say so. Please try 
what I committed.
04/19/2006 07:00:12 AM Jan Schneider Comment #2
State ⇒ Not A Bug
Reply to this comment
The scripts need to be fixed then. Your fix is not valid because it 
doesn't catch if you try to run the cli scripts on a localhost web 
server.
04/19/2006 04:41:24 AM dorm (at) dorm (dot) org Comment #1
State ⇒ Unconfirmed
Priority ⇒ 1. Low
Type ⇒ Bug
Summary ⇒ Horde_CLI::runningFromCLI() can erroneously return 'false' after Horde_CLI::init() is called
Queue ⇒ Horde Framework Packages
Reply to this comment
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');

          }

      }


Saved Queries