Short answer:
If none of the solutions on the web help you, try restarting your database server or allocating more RAM for it.
Extended answer:
I got the same problem a couple hours ago. It was all of a sudden, while I was editing some content in Wordpress admin panel.
In my case I am running a dev database server on my local machine.
Googling for the solution, I created a new script dbconnection.php
in the site root directory with the content as follows:
<?php
$link = mysqli_connect('localhost', 'root', '');
if (!$link) {
die('Could not connect: ' . mysqli_error($link));
}
echo 'Connected successfully';
mysqli_close($link);
Every third time (exactly) I was refreshing the page with that script I was getting message Could not connect:
or No input file specified
.
I opened my server logs (Apache) and this is what I saw:
[Thu Feb 06 14:04:51.101731 2020] [:error] [pid 30890:tid 139935881332480] [client 127.0.0.1:42729] FastCGI: server "/usr/lib/cgi-bin/php5.fcgi" stderr: PHP message: PHP Warning: fopen(/www/MY_VIRTUAL_HOST_DOMAIN/wp-content/languages/ru_RU.mo): failed to open stream: Too many open files in /www/MY_VIRTUAL_HOST_DOMAIN/wp-includes/pomo/streams.php on line 148, referer: http://MY_VIRTUAL_HOST_DOMAIN/wp-admin/post.php?post=250&action=edit ...
And a full stack trace.
So I understood that for some reason my database can't create more connections.
Defining a constant define( WP_ALLOW_REPAIR, true )
in the wp-config.php
didn't help.
Disconnecting all of my plugins didn't help either. I did a quick search if any of the PHP scripts don't do fclose()
after doing fopen()
.
Didn't try to extend maximum database connection limit, because I wanted to find a permanent solution.
So what I did is I shut down my virtual machine (the dev environment I am working in), restarted my PC, launched everything again and the problem didn't appear the second time.
No more errors in the logs.
So I guess my VM ran out of RAM exactly when I added some more data to the database. Which is very uncommon, because I have allocated a lot of RAM for it (11 GB out of 16 GB I have).
Hope this helps.