间歇性 - PHP警告:包括无法打开流:没有这样的文件或目录

I have an intermittent issue with the error include failed to open stream ...

99.9% of the time the includes works perfectly, but at peak times of the day I notice that I start getting an error appear in my php error log.

PHP Warning: include ('database.php') failed to open stream: No such file or directory

I only have one file with this include in it so I know full well its works, we have quite a few thousand requests a day with no issues, but out of these thousands of requests we seem to get around 10 a day which simply fail with the error PHP Warning: include ('database.php') failed to open stream: No such file or directory

It has driven me mad! - I have done some digging around to see what else is being requested from the IIS server at the same time and I can see that I am calling a separate php file which is unrelated to the file above. It simply counts the lines within my php error log and if there is an issue it will send an email....

I am wondering if for some reason there is some sort of file process limit that means if the error log is big enough the below code is doing something to PHP to stop it completeing file processes elsewhere such as includes ...

The basis of this code is :-

function getLines($file)
{
    $f = fopen($file, 'rb');
    $lines = 0;

    while (!feof($f)) {
        $lines += substr_count(fread($f, 8192), "
");
    }

    fclose($f);

    return $lines;
}

$phpcount = getLines("c:/windows/temp/php-errors.log");

I am wondering if for some reason there is some sort of file process limit that means if the error log is too large the above code struggles and PHP stops completing file processes elsewhere thus causing my includes problem ...

My guess is that the error comes from an include in the file that gets called only now and then. It could be the file that counts the log file lines, or the file that sends an email.

According to this checklist, the error seems to be that the problematic file is trying to include database.php using a relative path, and that fails because the current working directory is not the same.

The solution, as mentioned in the checklist, is to use absolute paths instead.

In any case, you should always use absolute paths in your includes. It is very likely to solve the problem.