开发者

PHP Suddenly stop searching for files in current directory

开发者 https://www.devze.com 2023-03-05 03:12 出处:网络
So I came up against something really strange today. I\'ve updated my PHP APC to the latest version and restarted apache. And then suddenly all scripts in apache starting complaining about not being

So I came up against something really strange today.

I've updated my PHP APC to the latest version and restarted apache. And then suddenly all scripts in apache starting complaining about not being able to find required files.开发者_运维百科

I would usually have:

require_once 'Abstract.php'

considering that Abstract.php is on the same directory as the other script.

The errors where:

PHP Warning: require_once(Abstract.php) [function.require-once]: failed to open stream: No such file or directory in data.php on line 411 PHP Fatal error: require_once() [function.require]: Failed opening required 'Abstract.php' (include_path='/var/www/application/../library:/var/www/library:.:/usr/share/php:/usr/share/pear') in data.php on line 411

As you can see the current directory (.) is included in the include_path of the execution. Why did this happen? Has anyone seen it before?


AFAIK, the . denotes the directory where the PHP binary resides. require* and include* functions take into account the current working directory, which can be modified via chdir().

As was suggested by cwallenpoole, try using the __DIR__ constant:

require_once __DIR__ . '/Abstract.php';

If that also fails, it means there's a misconfiguration elsewhere. If it works, it probably means the current executing PHP thread has its working directory set to a different and you need to either change the current working directory or modify the require statements to use absolute paths.

Also, have you considered using an autoload callback? That way you have a single point of entry for searching for classes.


Ok, I figured it out eventually and though I should share in case anyone else gets in the same trouble as me.

I used to have APC 3.0.x and upgraded to 3.1.8. As it seems APC on 3.1.8 has a bug that breaks include/requires of PHP.

See relative link here: http://pecl.php.net/bugs/bug.php?id=22687

Thanks everyone for the quick feedback :)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号