[英]What can cause a web server to not find an XML file?
I have a PHP script which reads from an xml file to generate a table. 我有一个PHP脚本,该脚本从xml文件读取以生成表。 The first thing it does is check to make sure the file exists. 它要做的第一件事是检查以确保文件存在。
$path = getcwd();
if(file_exists($path.'\inc\php\kbs.xml')){
$kbs = simplexml_load_file($path.'\inc\php\kbs.xml');
} else {
echo "Error: No KB file found";
}
For some reason, intermittently, it doesn't find the file. 由于某种原因,它间歇性地找不到文件。 I've tried removing the file_exists
check all together (since I know the file does exist) but it still doesn't load the file at times. 我尝试删除file_exists
一起检查(因为我知道该文件确实存在),但是它有时仍不加载该文件。 I can refresh the page and 7 times out of 10 it doesn't load, but sometimes it does. 我可以刷新页面,每10个页面刷新7次,但不会加载,但有时可以。
I never ran into this problem during development, but once it went production (being used by maybe 200 users now) it started happening. 在开发过程中,我从未遇到过这个问题,但是一旦投入生产(现在可能已有200个用户使用),它就开始发生。
How do I go about troubleshooting this? 我该如何解决此问题? (PHP 5.2.14 running on IIS) (在IIS上运行的PHP 5.2.14)
EDIT: Error logs give me the following messages when it fails: 编辑:错误日志失败时给我以下消息:
Notice: Undefined variable: kbs in <the path> on line 16
Notice: Trying to get property of non-object in <the path> on line 16
Warning: Invalid argument supplied for foreach() in <the path> on line 16
line 16 is the first time the variable $kbs
is accessed. 第16行是第一次访问变量$kbs
。 Obviously $kbs
isn't set if the file isn't found. 显然,如果找不到该文件,则不会设置$kbs
。
请使用绝对路径,相对路径会使事情变得一团糟。
Is the location relative to PHP? 位置相对于PHP吗? Do permissions allow the web server to see it? 权限是否允许Web服务器看到它?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.