fixing CLI check for servers using cgi-fcgi (PHP_SAPI is in those cases same for web and cli mode)

This commit is contained in:
Pepijn Over 2014-03-28 14:41:04 +01:00
parent 9c79bc90ec
commit 9866ab0c22
2 changed files with 15 additions and 4 deletions

View File

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

View File

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