我使用以下命令通过cron执行PHP文件
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 Have a file that's included in the execution that determines which config to load.... such as the following:
if (!strstr(getenv('HTTP_HOST'), "")) { $config["mode"] = "local"; } else { $config["mode"] = "live"; }当cron加载LIVE配置时,正在加载LOCAL配置。我试图使用http:// URL到文件,而不是绝对路径,但它没有找到该文件。是否需要更改命令以在其中使用URL?
The cron is loading the LOCAL config when it should be loading the LIVE config. I've tried using the URL to the file instead of the absolute path but it didn't find the file. Do I need to change the command to use a URL within it?
推荐答案使用此 php_sapi_name() 检查是否脚本在命令行上调用:
Use this php_sapi_name() to check if the script was called on commandline:
if (php_sapi_name() === 'cli' OR !strstr(getenv('HTTP_HOST'), "")) { $config["mode"] = "local"; } else { $config["mode"] = "live"; }如果要在命令行上使用live,请使用以下代码: / p>
If you want to use "live" on the commandline use this code:
if (php_sapi_name() === 'cli' OR strstr(getenv('HTTP_HOST'), "")) { $config["mode"] = "live"; } else { $config["mode"] = "local"; }更多推荐
通过cron执行PHP
发布评论