Execute PHP via cron - No Input file specified

后端 未结 6 1151
醉梦人生
醉梦人生 2021-01-14 02:13

I\'m using the following command to execute a PHP file via cron

php -q /home/seilings/public_html/dvd/cron/mailer.php

The problem is that I

6条回答
  •  说谎
    说谎 (楼主)
    2021-01-14 02:50

    Use this php_sapi_name() to check if the script was called on commandline:

    if (php_sapi_name() === 'cli' OR !strstr(getenv('HTTP_HOST'), ".com")) {
        $config["mode"] = "local";
    } else {
        $config["mode"] = "live";
    }
    

    If you want to use "live" on the commandline use this code:

    if (php_sapi_name() === 'cli' OR strstr(getenv('HTTP_HOST'), ".com")) {
        $config["mode"] = "live";
    } else {
        $config["mode"] = "local";
    }
    

提交回复
热议问题