Execute PHP via cron - No Input file specified(通过 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'), ".com")) {
$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'), ".com")) {
$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'), ".com")) {
$config["mode"] = "live";
} else {
$config["mode"] = "local";
}
这篇关于通过 cron 执行 PHP - 未指定输入文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:通过 cron 执行 PHP - 未指定输入文件
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- PHP - if 语句中的倒序 2021-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01