“(include_path='.:/usr/share/pear:/usr/share/php')"是什么意思? [英] what does it mean "(include_path='.:/usr/share/pear:/usr/share/php')"?

查看:84
本文介绍了“(include_path='.:/usr/share/pear:/usr/share/php')"是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 EC2 上有文件结构,例如:但面临一些文件引用问题.

I have file structure on EC2 like : but facing some file referencing problem.

index.php
-db
  -config.php
-cron
  -cron1.php

我尝试将文件引用为:

`require_once (dirname(__FILE__).'/db/config.php');`
`require_once (($_SERVER['DOCUMENT_ROOT']).'/db/config.php');`

但 cron 不运行.它在邮件中给出错误

but cron doesn't run.it gives error in mail as

`PHP Warning:  require_once(/db/config.php): failed to open stream: No such file or directory in /var/www/html/cron/cron1.php on line 3

Warning: require_once(/db/config.php): failed to open stream: No such file or directory in /var/www/html/cron/cron1.php on line 3

PHP Fatal error:  require_once(): Failed opening required '/db/config.php' (include_path='.:/usr/share/pear:/usr/share/php') in /var/www/html/cron/cron1.php on line 3

Fatal error: require_once(): Failed opening required '/db/config.php' (include_path='.:/usr/share/pear:/usr/share/php') in /var/www/html/cron/cron1.php on line 3`

推荐答案

如果你查看 PHP 常量 PATH_SEPARATOR,你会看到它是:"给你.

If you look at the PHP constant PATH_SEPARATOR, you will see it being ":" for you.

如果你把你的字符串.:/usr/share/pear:/usr/share/php"分开使用该角色,您将获得 3 个部分.

If you break apart your string ".:/usr/share/pear:/usr/share/php" using that character, you will get 3 parts.

  • .(这意味着您的代码所在的当前目录)
  • /usr/share/pear
  • /usr/share/php

任何对 include()/require() 的尝试,都将按此顺序在这些目录中查找.

Any attempts to include()/require() things, will look in these directories, in this order.

它在错误消息中向您显示,让您知道在何处找不到您试图要求的文件()

It is showing you that in the error message to let you know where it could NOT find the file you were trying to require()

对于你的第一个需求,如果它被包含在你的 index.php 中,那么你就不需要 dir 的东西,只要......

For your first require, if that is being included from your index.php, then you dont need the dir stuff, just do...

require_once ( 'db/config.php');

这篇关于“(include_path='.:/usr/share/pear:/usr/share/php')"是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆