Created
May 20, 2020 13:42
-
-
Save softsolution/8c49e9350bdfa33e4e1f7b25b7f91f2e to your computer and use it in GitHub Desktop.
Определение пути для настройки cron для InstantCMS2 после установки движка
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
define('DS', DIRECTORY_SEPARATOR); | |
define('PATH', dirname(__FILE__).DS); | |
define('DOC_ROOT', str_replace(DS, '/', realpath($_SERVER['DOCUMENT_ROOT']))); | |
$doc_root = DOC_ROOT.str_replace(DOC_ROOT, '', str_replace(DS, '/', dirname(PATH))); | |
$php_path = get_program_path('php'); | |
?> | |
<pre><?php echo $php_path ? $php_path : 'php'; ?> -f <?php echo $doc_root; ?>/cron.php <?php echo $_SERVER['HTTP_HOST']; ?> > /dev/null</pre> | |
<?php | |
function get_program_path($program){ | |
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'){ | |
//$which = 'where'; | |
return false; | |
} else { | |
$which = '/usr/bin/which'; | |
} | |
$data = execute_command($which.' '.$program); | |
if(!$data){ return false; } | |
return !empty($data[0]) ? $data[0] : false; | |
} | |
function execute_command($command, $postfix=' 2>&1'){ | |
if(!function_exists('exec')){ | |
return false; | |
} | |
$buffer = array(); | |
$err = ''; | |
$result = exec($command.$postfix, $buffer, $err); | |
if($err !== 127){ | |
if(!isset($buffer[0])){ | |
$buffer[0] = $result; | |
} | |
// проверяем, что команда такая есть | |
$b = mb_strtolower($buffer[0]); | |
if(mb_strstr($b,'error') || mb_strstr($b,' no ') || mb_strstr($b,'not found') || mb_strstr($b,'No such file or directory')){ | |
return false; | |
} | |
} else { | |
// команда не найдена | |
return false; | |
} | |
return $buffer; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment