Last active
January 17, 2017 15:51
-
-
Save dhaupin/7c88be87a543e59f5be9fb55c7b963a9 to your computer and use it in GitHub Desktop.
Function - CRON - Check out how PHP-CLI runs cron to understand various env vars
This file contains hidden or 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 | |
// Run this script with cron as php-cli under a user account (or root if using crontab -e). | |
// It will echo infos about the SAPI and server/environment variables | |
$php_cli[1] = ''; | |
if (isset($_ENV['_'])) { | |
$php_env = $_ENV['_']; | |
} elseif (isset($_SERVER['_'])) { | |
$php_env = $_SERVER['_']; | |
} else { | |
$php_env = ''; | |
} | |
preg_match('/.*(php-cli)/', $php_env, $php_cli); | |
echo 'PHP_SAPI: ' . PHP_SAPI . PHP_EOL . PHP_EOL; | |
echo 'php_sapi_name(): ' . php_sapi_name() . PHP_EOL . PHP_EOL; | |
echo 'preg_match() "php-cli": ' . $php_cli[1] . PHP_EOL . PHP_EOL; | |
foreach ($_SERVER as $key => $value) { | |
echo '$_SERVER[\'' . $key . '\']' . ': ' . $value . PHP_EOL . PHP_EOL; | |
} | |
foreach ($_ENV as $key => $value) { | |
echo '$_ENV[\'' . $key . '\']' . ': ' . $value . PHP_EOL . PHP_EOL; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment