可能重复:
What is the canonical way to determine commandline vs. http execution of a PHP script?如何确定是否PHP被运行命令行
我有时从命令行运行PHP脚本。用cron或其他一次性脚本。
我想知道它是否可能在php脚本中以确定它是否通过命令行运行?
<?php
$isRunFromCommandLine = // set to (true:false) -- not sure how to do this
if($isRunFromCommandLine){
echo 'You are running from command line';
}
else{
echo 'You are not running php via command line'
}
?>
你是正确的,它是重复的。我最初的搜索没有找到它。我不认为它的标题非常好?感谢您的链接+1。 –