How to Fix the “Warning: File_Get_Contents” Error
There’s a WordPress error that’s frustrating to no end because if you’ve come across it, you probably didn’t actually do anything wrong. Still, plastered across your site will be these words:
Warning: file_get_contents(path/to/wordpress/file): failed to open stream: No such file or directory in /path/to/another/wordpress/file.php on line #
The error message itself is almost misleading because it lists two files and a line number at the end, which would otherwise indicate a specific issue within a file if it were a different error, though, this isn’t always the case.
Most often, this error is an indication that your hosting provider has set limits on your resources, namely, on open stream requests and you have started exceeding them. It could also be a conflict with a plugin you’re using, usually due to these limits.
In this post, I’ll show you how to troubleshoot the “Warning: file_get_contents” error in WordPress to pinpoint the cause, then, I’ll show you how to resolve it.
Have You Tried Turning It Off and On Again…?
The first place to look when you begin troubleshooting is the error message. The files that are listed should give you a clue since one or both of them likely point to a script or plugin file such as /home/username/public_html/wp-content/plugins/plugin-name/problem-file.php.
If you see a similar file path in the error you’re seeing, contact the plugin author and provide them with the exact error you’re seeing.
Typically, the plugin author can make a slight adjustment to compensate for hosting providers that cap resources.
It doesn’t mean the plugin you’re using is terrible. Not by a long shot. It just means there’s a better way to add the code they need for the plugin so it’s compatible with your host.
In the meantime, you can disable the plugin so you can get rid of the error until the plugin author can push an update to fix the issue.
Use Some Debug Spray
Additionally, you can turn on the WordPress debugging mode to get additional information about the error.
Be sure to also enable logging so error messages are displayed in a private log among your files instead of publicly in the front-end. This helps prevent hackers from taking advantage of the possible sensitive information that’s displayed in the errors.
You can find the details on enabling debug mode and error logging by checking out the post Debugging WordPress: How to Use WP_DEBUG.
Once you have collected some details in your error log and if you have determined that a plugin you’re using is the cause, you can send the log to the plugin author.
If it comes down to it and you need to contact your host, you can also send them the error log, but more on that later.
Flip the Switch to “On”
There’s one adjustment you can make yourself to your php.ini file that works in some cases. If you don’t have a php.ini file, check for a php5.ini file instead.
It may be hidden, which means you would need to access your file settings and select the option to show all files.
For details on editing php.ini file and how to enable showing all files, check out How to Increase the Maximum Upload and PHP Memory Limit in WordPress.
Once you found the file, open it and check for the following line:
If you see it, switch
on so it looks like this:
Then, save the file. Your issue should be resolved, though, it’s important to note that this should only be considered a temporary solution.
The purpose of this line is to disable PHP functions of retrieving data from remote locations. Some hosting providers include this line to help prevent SQL injections. For more details about this type of hacking, check out The Ultimate Guide to WordPress Spam.
Since it can help secure your site, it’s best not to adjust this line and contact your host instead, though, if you want your site up while this issue is resolved permanently, this can be a good option in the meantime.
Just be sure you implement other best practices when it comes to site security to help keep your site secure while you resolve this issue. Installing a security plugin such as Defender can help tremendously.
Send in the Cavalry!
In most cases, the best way to resolve this issue is to contact your hosting provider since the issue is typically related to limits they set on your plan.
To help clarify the issue with them, be sure to provide the full error message and it can also help to send your error log as well.
Keep in mind that sometimes, there isn’t a whole lot your host can do because they put those limits in place for a reason. They may be able to make an exception for you, but this ultimately may be a sign for you to upgrading your hosting plan to something that offers more resources.
You can check out Shared, VPS, Dedicated or Cloud Hosting? Which is Best for WordPress? for details on the different types of hosting.
Holding Out for a (Super) Hero
If you’re still experiencing issues and don’t know where to turn, let us help you! Our expert support heroes are ready and waiting to help you with whatever WordPress issue you’re experiencing.
You can ask your question for free if you’re already a member.
If you’re not a member yet, you can sign up for a free trial and our support team will help you with any WordPress issue, big or small.
The “Warning: file_get_contents” error may not be your fault at all, but now you know how to troubleshoot the issue and you also know the steps you can take to resolve the issue.
Even if you aren’t experiencing this issue at the moment, you can keep these details in your back pocket in case it comes up in the future.Tags: