[英]Include file in PHP but SSH occurring error
I am able to access the PHP page in the web browser without error and works.我能够在 web 浏览器中访问 PHP 页面而不会出错并且可以正常工作。 (error display active)
(错误显示激活)
But when I want to access the PHP page via SSH I get some errors.但是当我想通过 SSH 访问 PHP 页面时,我遇到了一些错误。
PHP Warning: include_once(/app/config.php): failed to open stream: No such file or directory in /home/example/public_html/app/cron/cronMin.php on line 7
SSH Command: SSH 命令:
/usr/local/cwp/php71/bin/php -d max_execution_time=18000 -q /home/example/public_html/app/cron/cronMin.php
cronMin.php
: cronMin.php
:
<?php
use Carbon\Carbon;
ini_set('memory_limit', '3G');
ini_set('max_execution_time', 180);
include $_SERVER['DOCUMENT_ROOT'] . '/app/config.php';
...
What is the reason for this?这是什么原因?
PHP 7.4 - Apache, Nginx, and Varnish PHP 7.4 - Apache、Nginx 和清漆
From the $_SERVER documentation :从$_SERVER 文档:
The entries in this array are created by the web server.
此数组中的条目由 web 服务器创建。
When running PHP on the command line, there is no web server involved, that means no $_SERVER['DOCUMENT_ROOT']
.在命令行上运行 PHP 时,没有涉及 web 服务器,这意味着没有
$_SERVER['DOCUMENT_ROOT']
。
If your scripts must run the same with the CLI SAPI and a web server SAPI, don't rely on such variables.如果您的脚本必须与 CLI SAPI 和 web 服务器 SAPI 一起运行,请不要依赖此类变量。 To include other PHP scripts, use the
__DIR__
magic constant instead:要包含其他 PHP 脚本,请改用
__DIR__
魔术常量:
// cronMin.php is in the "app/cron" directory, this will be the value of __DIR__ as an absolute path
include __DIR__ . '/../config.php';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.