gpt4 book ai didi

PHP include_once 在本地工作但调用 cron 不工作

转载 作者:行者123 更新时间:2023-12-01 22:17:43 25 4
gpt4 key购买 nike

我使用 include_once 在 php 中包含文件,它将在本地主机中工作,但使用 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 Warning: include_once(/cloud/references/library.php): failed to open stream: No such file or directory in /var/www/html/cloud/cloud_ip_automation/cron_all.php on line 3

Warning: include_once(/cloud/references/library.php): failed to open stream: No such file or directory in /var/www/html/cloud/cloud_ip_automation/cron_all.php on line 3

PHP Warning: include_once(): Failed opening '/cloud/references/library.php' for inclusion (include_path='.:/usr/share/pear:/usr/share/php') in /var/www/html/cloud/cloud_ip_automation/cron_all.php on line 3

Warning: include_once(): Failed opening '/cloud/references/library.php' for inclusion (include_path='.:/usr/share/pear:/usr/share/php') in /var/www/html/cloud/cloud_ip_automation/cron_all.php on line 3

最佳答案

从 CLI 运行时未设置 $_SERVER 变量。您必须使用 dirname(__FILE__) 并使路径相对于当前文件。

例如在你的情况下,是这样的:

include_once(dirname(__FILE__).'/../'.project_name.'/references/library.php');

关于PHP include_once 在本地工作但调用 cron 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43385671/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com