Include/require work but include_once/require_once suddenly do not


Several of my PHP (7.2) apps stopped working this morning if they use include_once or require_once, but they worked fine yesterday. The same code also works fine on the same server, but other domains with minimal difference in vhost configs and no htaccess files (Apache 2.4). Also, things work if I chase down the error and remove “_once” from everything. I’ve been using PHP for almost 20 years and never seen anything like this. The error I get looks like the following, but it happens for any include_once/require_once.

include_once(): Failed opening ‘/whatever_path/whatever_file.php’ for inclusion (include_path=’.:/usr/share/php’) in /another_path/another_file.php on line 24



Sounds like the path is different, not that the call is wrong.


But it works fine if I do


Just not


That is odd. My first thought was that the file is already included and that would prevent it from including it again, but that wouldn’t throw the error…


Right. I thought that too, but as you said that wouldn’t result in an error.


Php has a reoccurring history of the _once() statements not working due to not being able to normalize and figure out the real path of files. This however is php version specific. Has your php version been changed by you or your hosting?

There should be a second error message before the one you posted stating why php thinks the file cannot be included/required.

Is there a reason you are not using just ‘require’? The _once() versions are actually slower because they must examine the list of already included/required files.


There is no second error. I do realize the _once versions are a little slower, but it isn’t substantial for our environment. We are using it largely because some of the third-party code we have uses it, such as SimpleSAMLphp. As I said, I could chase down all the _once’s and remove them, and I actually did that for some critical apps to get them back up, but I have so many apps that I would really like to fix the core issue.


I forgot to mention the PHP version has not changed (7.2). I manage the server myself, not hosted. It is running Ubuntu 18.04 LTS, and nothing has changed since these things were all working yesterday afternoon.


Is php running as an Apache server module or as a CGI application? If a as a server module, the _once() mechanism may have become corrupted or you found a bug, and restarting the web server may (temporarily) clear the problem.


It is running through mod_php. I did restart apache, and even the server entirely. Unfortunately, that did not clear the problem. It may be a bug. We are in the process of eradicating the use of once_ in all of our applications for now. Thanks for trying.


I do not have a quarter of the experience combined by posters in this thread. I am simply adding my own experience which may or may not be helpful.

I had this problem a few months ago. I started using include_once and it worked. Suddenly, i started getting errors like the errors mentioned by the op. I tried many hack jobs and nothing seemed to work except simple include statements:

include '/dir/file.php';
include '../../dir/file.php';

i switched to require with dirname and i no longer have problems:

require dirname(__FILE__) . '/file.php';

i think it may have something to do with file paths and whether or not the file is accessed by other pages. try looking into the path to see if you can retain the include_once code. Otherwise, you may have to switch all of the code to something more stable.