dongpo2002 2016-06-02 23:18
浏览 156

间歇性 - 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 ...

  • 写回答

1条回答 默认 最新

  • doumuyu0837 2016-06-12 10:19
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效