当我从命令行运行我的
PHP脚本时,我收到以下通知.我假设原因是这些变量如SERVER_NAME在没有浏览器的情况下运行时不适用.
在我的代码中,如何检测它是从命令行运行并跳过这些行,所以我不必看到这些通知?
我不想通过管道到/ dev / null阻止这些通知,我宁愿增强PHP代码.
david@ubuntu:/var/www/user$php cron_email.php
PHP Deprecated: Comments starting with '#' are deprecated in /etc/php5/cli/conf.d/mcrypt.ini on line 1 in Unknown on line 0
PHP Notice: Undefined index: SERVER_NAME in /var/www/user/codestart.php on line 14
PHP Notice: Undefined index: REMOTE_ADDR in /var/www/user/codestart.php on line 97
PHP Notice: Undefined index: REQUEST_URI in /var/www/user/codestart.php on line 99
PHP Notice: Undefined index: HTTP_REFERER in /var/www/user/codestart.php on line 100
PHP Notice: Undefined index: REQUEST_METHOD in /var/www/user/codestart.php on line 101
PHP Notice: Undefined index: HTTP_USER_AGENT in /var/www/user/codestart.php on line 102