本文及子页面整理了在 PHP 编程中遇到一些问题以及编程中的技巧。
判断是否为命令行执行
What is the canonical way to determine commandline vs. http execution of a PHP script?」
<?php
if (php_sapi_name() == "cli") {
// In cli-mode
}
// If the PHP version is 4.2.0 or higher)
if (PHP_SAPI === 'cli') {
// In cli-mode
}