【发布时间】:2017-09-09 04:28:50
【问题描述】:
我使用 include_once 在 php 中包含文件,它可以在 localhost 中运行,但使用 cron 运行相同的文件会显示错误
File name : cron_all.php
<?php
define('project_name','/cloud');
include_once($_SERVER['DOCUMENT_ROOT'].project_name."/references/library.php");
?>
错误:
[root@xx-xxx-xx~]#php /var/www/html/cloud/cloud_ip_automation/cron_all.php
PHP 警告:include_once(/cloud/references/library.php):未能 打开流:中没有这样的文件或目录 /var/www/html/cloud/cloud_ip_automation/cron_all.php 在第 3 行
警告:include_once(/cloud/references/library.php):打开失败 流:中没有这样的文件或目录 /var/www/html/cloud/cloud_ip_automation/cron_all.php 在第 3 行
PHP 警告:include_once():打开失败 '/cloud/references/library.php' 用于包含 (include_path='.:/usr/share/pear:/usr/share/php') 在 /var/www/html/cloud/cloud_ip_automation/cron_all.php 在第 3 行
警告:include_once():打开失败 '/cloud/references/library.php' 用于包含 (include_path='.:/usr/share/pear:/usr/share/php') 在 /var/www/html/cloud/cloud_ip_automation/cron_all.php 在第 3 行
【问题讨论】:
-
您在错误的目录中搜索。也许
$_SERVER['document_root']没有指向你认为它指向的地方。