通过 cron 执行 PHP

编程入门 行业动态 更新时间:2024-10-24 10:28:13
本文介绍了通过 cron 执行 PHP - 未指定输入文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下命令通过 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 正在加载本地配置,而它应该加载实时配置.我试过使用文件的 http://URL 而不是绝对路径,但没有找到该文件.我是否需要更改命令以使用其中的 URL?

The cron is loading the LOCAL config when it should be loading the LIVE config. I've tried using the http:// 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",请使用以下代码:

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 - 未指定输入文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-03-27 04:24:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/678925.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:cron   PHP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!