How to determine if a PHP file is loaded via cron/command line

前端 未结 4 538
长情又很酷
长情又很酷 2020-12-06 02:45

I need to determine whether the PHP file is being loaded via cron or command line within the code. How can I do this?

4条回答
  •  再見小時候
    2020-12-06 03:11

    You can check the PHP_SAPI constant to check if the CLI interpreter is being used:

    $is_cli= PHP_SAPI == 'cli';

提交回复
热议问题