From 9866ab0c22df02d80ff022eb9d9cd50e5188cda9 Mon Sep 17 00:00:00 2001 From: Pepijn Over Date: Fri, 28 Mar 2014 14:41:04 +0100 Subject: [PATCH] fixing CLI check for servers using cgi-fcgi (PHP_SAPI is in those cases same for web and cli mode) --- cron/status.cron.php | 8 ++++---- src/includes/functions.inc.php | 11 +++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/cron/status.cron.php b/cron/status.cron.php index 8ed21f76..5145b4b3 100755 --- a/cron/status.cron.php +++ b/cron/status.cron.php @@ -25,13 +25,13 @@ * @link http://www.phpservermonitor.org/ **/ -if(php_sapi_name() != 'cli') { - die('This script can only be run from the command line.'); -} - // include main configuration and functionality require_once dirname(__FILE__) . '/../src/bootstrap.php'; +if(!psm_is_cli()) { + die('This script can only be run from the command line.'); +} + // prevent cron from running twice at the same time // however if the cron has been running for X mins, we'll assume it died and run anyway // if you want to change PSM_CRON_TIMEOUT, have a look in src/includes/psmconfig.inc.php. diff --git a/src/includes/functions.inc.php b/src/includes/functions.inc.php index 709a64c3..90ec504b 100755 --- a/src/includes/functions.inc.php +++ b/src/includes/functions.inc.php @@ -432,6 +432,17 @@ function psm_POST($key, $alt = null) { } } +/** + * Check if we are in CLI mode + * + * Note, php_sapi cannot be used because cgi-fcgi returns both for web and cli + * source: https://api.drupal.org/api/drupal/includes!bootstrap.inc/function/drupal_is_cli/7 + * @return boolean + */ +function psm_is_cli() { + return (!isset($_SERVER['SERVER_SOFTWARE']) && (php_sapi_name() == 'cli' || (is_numeric($_SERVER['argc']) && $_SERVER['argc'] > 0))); +} + ############################################### # # Debug functions