可能重複:
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。 –