Skip to content

Instantly share code, notes, and snippets.

@dhaupin
Last active January 17, 2017 15:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dhaupin/7c88be87a543e59f5be9fb55c7b963a9 to your computer and use it in GitHub Desktop.
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
<?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