mysql error mysqli_real_connect() - php

I have a Wordpress site that started receiving an error when I hit the homepage. The error is:
Warning: mysqli_real_connect(): (HY000/2002): Only one usage of each socket address (protocol/network address/port) is normally permitted. in D:\home\site\wwwroot\wp-includes\wp-db.php on line 1538
I was able to get it back up after I created a new db and restored from backup but after a few minutes I started getting the error again. The site is hosted in Azure and the mysql db is hosting cleardb. Any help you can provide as to why I am getting this error would be helpful. I have updated Wordpress to the latest version and updated php to version 7 but that did not fix the error. Any body point me in the right direction?

Related

PHP Site works in Mobile but in Desktop it says mysqli::real_connect(): (HY000/2002)

I Hope you can help me.
When I access my website in a desktop browser it gives me a connection error:
A PHP Error was encountered
Severity: Warning
Message: mysqli::real_connect(): (HY000/2002): No such file or directory
Filename: mysqli/mysqli_driver.php
Line Number: 203
If I access my website in a mobile browser, it doesn't show the error and I can access the site ok.
If I use a desktop browser like Chrome, open Developer Tools (F12) and select a Mobile User Agents it also works.
I don't know where to look for a solution. Could you please give me some troubleshooting tips?
Im using PHP 7.4 / Codeignter 3.1.1
Thanks !
EDIT: I've translated the error message to english
I fixed this but doing the following:
I restore in cpanel my files to a backup of 5 days earlier.
In Cloudfare, I did a purge all cache.
I don't know what happen, I believe it's related to cache and htaccess but i didn't know how to troubleshoot it.
I post my answer so if anyone in the future see this know what I did.

PHP (5.5.7) Warning connecting to MySQLi in Windows Servers 2008 R2

I'm running Moodle on PHP 5.5.7 64bit nts on Windows Server 2008 R2 with MySQL 5.5.36.
Up until two days ago, there were no problems. To deal with Xdebugger being such a memory hog, an extra CPU and more memory was assigned to the virtual machine. The Windows license was also activated. The entire vm was rebooted. (I had restarted the machine before prior to this, with no problems).
I am now receiving the following warning when I access any page on the site:
PHP Warning: mysqli::mysqli(): (HY000/2002): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
in C:\inetpub\wwwroot\moodle\lib\dml\mysqli_native_moodle_database.php on line 375
I created a test php page that simply consists of the following:
$mysqli = new mysqli("127.0.0.1", "moodleuser", 'xxxx', "moodle", 3306);
if ($result = $mysqli->query("SELECT * from mdl_user limit 10")) {
echo "Select returned $result->num_rows";
} else {
echo "Error";
}
$mysqli->close();
I receive the following output:
PHP Warning: mysqli::mysqli(): (HY000/2002): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.in C:\inetpub\wwwroot\moodle\info.php on line 17
PHP Warning: mysqli::query(): Couldn't fetch mysqli in C:\inetpub\wwwroot\moodle\info.php on line 18
PHP Warning: mysqli::close(): Couldn't fetch mysqli in C:\inetpub\wwwroot\moodle\info.php on line 24
I have checked that "127.0.0.1 localhost" exists in my hosts file and that the IPv6 "::1" line has been commented out.
I have also attempted to use "localhost" but same problem.
The bizarre thing is that if I refresh the page, occasionally, and completely at random, the warning doesn't occur and the correct output is given.
I have attempted to disable the warnings, but php appears to be ignoring me. Also, disabling the warning is not exactly ideal.
Any ideas?
EDIT:
So after much pain staking back and forths between PHP and MySQL and IIS, it looks like (once again) it was php.ini to blame.
To be honest, I cant even tell you which setting was the problem - but I changed all possible timeout related settings in php.ini to a large number (10000 or -1 depending on the setting), as well as the connection_timeout for mysql in my.ini.
I am still yet to figure out which one was causing the problem, but will edit this post if I ever do.
So after much pain staking back and forths between PHP and MySQL and IIS, it looks like (once again) it was php.ini to blame.
To be honest, I cant even tell you which setting was the problem - but I changed all possible timeout related settings in php.ini to a large number (10000 or -1 depending on the setting), as well as the connection_timeout for mysql in my.ini.
I am still yet to figure out which one was causing the problem, but will edit this post if I ever do.

Intermittent error connecting to my localhost MySQL instance from PHP: mysqli_connect(): HY000/2013

I have a LAMP website (PHP/MySQL), and I rely heavily on my MySQL database.
Recently, the following error started occurring intermittently:
[30-Oct-2011 16:11:49] PHP Warning: mysqli_connect() [<a href='function.mysqli-connect'>function.mysqli-connect</a>]: (HY000/2013): Lost connection to MySQL server at 'sending authentication information', system error: 32 in /home/path/to/my/code.php on line 1029
This is line 1029, the specific line that occasionally gives the above error:
$db = mysqli_connect($cfg['db_location'], $cfg['db_reader_username'], $cfg['db_reader_password']);
where $cfg['db_location'] is "localhost", and the username and password are correct.
It appears as though something is causing my PHP script to intermittently lose connection to the MySQL server, which is puzzling to me because all of my MySQL connections are made to localhost. That is, the PHP script and the MySQL server are both running on the same box, and I connect to MySQL via localhost.
Additionally, this is puzzling because my PHP script is able to successfully connect to the MySQL server for perhaps 90% of pages.
As best I can tell, my server has plenty of available RAM and CPU:
top - 16:38:23 up 173 days, 19:19, 2 users, load average: 0.57, 0.78, 0.84
Tasks: 142 total, 4 running, 137 sleeping, 0 stopped, 1 zombie
Cpu(s): 18.7%us, 27.5%sy, 0.7%ni, 52.6%id, 0.2%wa, 0.1%hi, 0.2%si, 0.0%st
Mem: 2976260k total, 1861368k used, 1114892k free, 532628k buffers
Swap: 2048248k total, 116k used, 2048132k free, 1035804k cached
And plenty of available disk space. When I run df -h, all of my filesystems are at most 25% in use.
So I don't know what would be causing the sporadic errors that I'm seeing in my PHP error logs.
Any ideas what might be causing my PHP script to intermittently lose connection to my MySQL server on localhost?
I upgraded to MySQL 5.1, and this is now what get when I run mysql -V:
mysql Ver 14.14 Distrib 5.1.56, for pc-linux-gnu (i686) using readline 5.1
The same errors are still happening, though:
[30-Oct-2011 20:26:18] PHP Warning: mysqli_connect() [<a href='function.mysqli-connect'>function.mysqli-connect</a>]: (HY000/2013): Lost connection to MySQL server at 'sending authentication information', system error: 32 in /home/path/to/my/code.php on line 1029
As before, the errors continue to be intermittent.
After I upgraded to MySQL 5.1, I've been looking carefully at my PHP errors logs. I've noticed a few other errors similar to the first one. For example, here's one such error:
[30-Oct-2011 22:42:29] PHP Warning: mysqli_connect() [<a href='function.mysqli-connect'>function.mysqli-connect</a>]: (HY000/2013): Lost connection to MySQL server at 'reading authorization packet', system error: 104 in /home/path/to/my/code.php on line 1029
And here's another error I've seen in my logs:
PHP Warning: mysqli::mysqli() [<a href='mysqli.mysqli'>mysqli.mysqli</a>]: (HY000/2002): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /home/path/to/different/code.php on line 7
In all cases, the problem fundamentally seems to be a failure to connect to MySQL. Any ideas what might be causing this or how I could debug it?
Perhaps this bug report will help - It seems that a fix may be to set a higher timeout for the global connect_timeout. It was set to a higher value in later versions of MySQL 5.1 (10 seconds) as opposed to 5 seconds for earlier versions.
http://bugs.mysql.com/bug.php?id=28359

More than max_user_connections in CodeIgniter app?

I'm getting what looks like rather serious database errors in my CodeIgniter application. In the log file it says:
User anders already has more than 'max_user_connections' active connections
And there are several hundred of those lines... I've read a bit by Googling, and some suggested that it was because you didn't close the connection after it was used, but others said that this was nonsense, and that the connection was automatically closed (which is what I read in the docs too).
Also, later in the log file, I have these error messages:
ERROR - 2011-10-12 10:50:19 --> Severity: Warning --> file_get_contents(http://localhost/expertinfo/error/error_general) [function.file-get-contents]: failed to open stream: HTTP request failed! /Applications/MAMP/htdocs/expertinfo/application/errors/error_general.php 4
This seems to have something to do with the fact that I'm using a custom error page by using
echo file_get_contents($config['base_url'] . 'error/error_db');
to redirect to a custom page.
Finally, I'm also getting:
ERROR - 2011-10-12 10:52:19 --> Severity: Warning --> mysql_pconnect() [function.mysql-pconnect]: Can't connect to MySQL server on 'mydb24.surftown.se' (4) /Applications/MAMP/htdocs/expertinfo/system/database/drivers/mysql/mysql_driver.php 88
In these last two, I don't understand what the local path is doing there (The path to my CodeIgniter app on my computer). I mean this is a part of the system folder and the one on the remote server should be used, right? I have the database set up as the remote database, and I don't have any local paths as far as I know....
So why does this happen, and what can I do about it?
Please help, this seems rather urgent. I'm a bit of a newbie to both php and CodeIgniter too, so a clear and simple answer would be greatly appreciated!
Local path as I see shows you file where your error happened, because your driver /Applications/MAMP/htdocs/expertinfo/system/database/drivers/mysql/mysql_driver.php possible on it's 88 line contain connect() function and it raise an exception
The problem is with your mydb24.surftown.se remote server, you should check your access credentials, etc. to find what exactly happened
Just an FYI, mysql_pconnect is usually a bad practice on shared hosting (you can see why here:http://stackoverflow.com/questions/1830830/advantages-disadvantages-of-pconnect-option-in-codeigniter)
You might just disable pconnect on application/config/database.php and see the error going away as your connections will be realluy lower.
For the quote: "mysql_pconnect is usually a bad practice on shared hosting".
I changed to use mysql_connect. It made no difference.

PHP MySQLi query - "Permission denied" [duplicate]

This question already has an answer here:
Connect DATABASE Error TYPE: 2002: Permission denied
(1 answer)
Closed 3 years ago.
Im using PHP MySQLi to connect to MySQL and sometimes doing query i get error:
"Permission denied" error code: 2002.
The strange thing is that it happens for different query's and totally unpredictable. For example it might happen on third query after first two executed correctly.
I know it is not problem with MySQL because i moved it from one server to another and problem still persists. Most likely problem with PHP or interconnection between PHP and MySQL servers (they're on different machines)
Anyone got ideas?
EDIT:
query what gets "Permission denied" works if i restart script - its not permissions problem
ERROR:
[23-Apr-2011 19:00:02] PHP Warning:
mysqli::mysqli() [mysqli.mysqli]:
[2002] Permission denied (trying to
connect via
tcp://xxx.xxx.xxx.xxx:3306) in
/home/.../DB.php on line 19
[23-Apr-2011 19:00:02] PHP Warning:
mysqli::mysqli() [mysqli.mysqli]:
(HY000/2002): Permission denied in
/home/.../DB.php on line 19
Same things happened on my environment. And the cause was SELinux.
You might be able to connect the database by executing php from command line
while you might not by executing on the web server.
In my case, I turned off SELinux.
# setenforce 0
Or you have to set up SELinux correctly.
I think the database user do not have sufficient permission to make particular operation on particular mysql table.
This isn't a permissions error. The client isn't able to get as far as connecting to the database, let alone trying to authenticate the user.
I suspect these problems will be being caused by either network problems (preventing the client/server machines from talking to each other) or the MySQL server process not running on the remote host.
The error code is documented here: http://dev.mysql.com/doc/refman/5.5/en/can-not-connect-to-server.html
Check The Permissions for the user that you are connected through

Categories