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

前端 未结 4 540
长情又很酷
长情又很酷 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:19

    The most reliable and exhaustive way to check where your script is run known to me is

    php_sapi_name()

    Neither this nor any of the other listed methods listed here, however, will give you a distinction between "normal" CLI mode, and a cron call. gahooa's command line argument idea is probably the best and most reliable solution.

提交回复
热议问题