简体   繁体   中英

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. 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. I can refresh the page and 7 times out of 10 it doesn't load, but sometimes it does.

I never ran into this problem during development, but once it went production (being used by maybe 200 users now) it started happening.

How do I go about troubleshooting this? (PHP 5.2.14 running on IIS)

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. Obviously $kbs isn't set if the file isn't found.

请使用绝对路径,相对路径会使事情变得一团糟。

Is the location relative to PHP? Do permissions allow the web server to see it?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM