mysqli over ssl giving 2003 - php

I'm using mysqli connection over ssl,
so using in code following:
$mdbconnection = mysqli_init();
$mdbconnection->ssl_set('/ssl/xyz.pem', '/ssl/abc-cert.pem', NULL, NULL, 'AES256-SHA');
$mdbconnection->real_connect(SV_SERVER, SV_MYSQL_LOGIN, SV_MYSQL_PASSWORD, SV_MYSQL_DATABASE);
I noted down that I am not able to connect over mysql server all the time.
if trying 100 times failing 3 time.
and getting following error
echo($mdbconnection->connect_errno);
printing:
2003
and if I am trying second time after failing it{echo($mdbconnection->connect_errno);} will give always 1045.
I am trying to solve this bug.
Any ideas would be appreciated.

The 2003 error code means the connection couldn't be established:
https://dev.mysql.com/doc/refman/5.5/en/error-messages-client.html
Error code 1045 means the client connected but the server rejected the credentials (access denied):
https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html
I'd say that if you're getting the 2003 error code a few times out of every 100 tries, it sounds like some of the possibilities could be:
Some intermediate application or piece of hardware might be seeing your attempts as a possible flood attack (DDoS) and could be intercepting and blocking the connection (if you're connecting 100 times really quickly)
You might have some network stability issues on the client side. It might be worth the time to run Wireshark and reproduce the problem with it running in order to capture the problem and see if it shows anything significant (e.g. DNS failure).
The MySQL server might be crashing and then restarting. Check your server-side MySQL error log (https://dev.mysql.com/doc/refman/5.7/en/error-log.html). Actually, you should really do this as a first step any time you have bizarre behavior in MySQL.
If the MySQL server log doesn't show anything, check your system logs, especially if you're logging anything like blocked firewall (iptables or whatever f/w you're using) packets and search them for your client IP around the time of the problem.
Finally, if you can reproduce this easily/quickly (e.g. make 100 connections via a script and see it fail), try eliminating SSL out of the equation and connecting without SSL and see if it gives you the same problem. If it works flawlessly without SSL, perhaps there's a problem with the SSL library that was used during the compilation of your MySQL package.
You might also want to check to see if you have any load-balancing in place that might make your script connect to different instances of the MySQL server (this is less likely, but could explain the symptoms you're seeing if one server is down and the next doesn't have the credentials you're providing)

Related

err_connection_timed_out and PHP Warning: mysqli_connect():(HY000/2002):Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'

Recently, from few weeks ago I got err_connection_timed_out just sometimes while working with my website.
and i am sure, my users get this error too.
When i see at error log, there are a few of message like below
PHP Warning:mysqli_connect(): (HY000/2002): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock
I changed 'localhost' to '127.0.0.1' for TCP connection instead of Unix socket, but no success.
My server host admin do not accept any problem at server side (like always!).
I asked them to restart Mysql, but they do not accept because it is a share server.
It is a Directadmin server and they recommend switch to Cpanel as the last chance.
Do you have any experience and solution for this problem?
EDIT: The main problem is err_connection_timed_out which i get in browser and i don't know if it relates to Mysql connection error in log file.
Switching might have positive effects because it's differently setup.
But if it happens sometimes it is probably the MYSQL server is burping.
Lately it's normal that the services has limit per user; so you can try to enable cache (of that is possible); to see whether it's less frequent (might be some queries that is running long).
do you have any cronjobs running or other processes around the time you receive those errors?
Normally this problem is caused due to MySQL server timing-out database connections is faster than the Stash connection pool can notice. This exhausts the Stash connection pool as it will keep its connections open while the MySQL side of the connections is already closed.
Easiest solution.
You can fix it by simply change this parameter (wait_timeout) at the Mysql config.
More difficult but better
Also you can close all connections in your code after you got the values. And finally you can change your connection to your database in order to reuse an existing connections.
And last but not least
Try a vps you got out there too many oferts, even for free. You wouldn't be able to change anything in a shared host sorry. :(

postgresql query hangs indefinitely over VPN - new firewall

We have a product where a local linux machine "SCANNER" does some polling on a local network and then stuffs information into a database in our cloud server over an OpenVPN connection, using pg_query (server is running PostgreSQL 9.5.5).
There is a PHP (5.5.9) daemon on SCANNER that checks the database in a 'while' loop for work to be done. This has always worked great, and continues to work great on all of our client networks, except for one, which has recently developed a bizarre problem.
After they upgraded their firewall (a Checkpoint 5200, and as far as we can tell, all the rules are correct to allow traffic from SCANNER to our cloud server over the VPN), one query in one script hangs indefinitely. Here are the symptoms we have noted:
Most of the time, the query works fine and the script continues. Every once in a while tough, the pg_query() call blocks and never returns. It's not that there's an error; the call literally blocks forever (or many hours until we manually restart).
This query has been the same for a long time, and we have never had this problem at any of our other clients, nor at this client until they changed their firewall.
We can tell from watching the pg_stat_activity table on the cloud server that the query does make it to the cloud, and then sits in that table forever. In every case, pg_stat_activity.state='idle' and pg_stat_activity.waiting=false
During this time, we can still ping the cloud server from SCANNER over the VPN, and we can continue to successfully query its remote database from other scripts on SCANNER, and from SCANNER's command line.
This client happens to have two different SCANNER machines, on different subnets but behind the same firewall. This problem can occur at any time on either one, but doesn't necessarily occur at the same time on both (at least not with any statistical significance).
If we restart the daemon, the problem is temporarily resolved. But it usually recurs sometime between 2 seconds and a few hours later.
We are looking for any input that might solve the problem, whether it is related to our application or the firewall itself (which we have been given permission to modify as needed). Feel free to ask any clarifying questions.
Thanks in advance!
Check Point firewall has a lot of advanced threat protections, depending of acquired blades, the device can be blocking communication between your database and application. Try to use Check Point log tools (Tracker, SmartEvent or NGSE) to filter Firewall logs. Filter all events where your source or destination are your Scanner or database server IP adresses. If you get some drop ou block into your TCP Packets, logs will show that.
If your firewall topology uses Cluster configurations try to check your configuration, it could be misconfigured and database TCP session are active but packets are using another network path.
If you are using Check Point VPN Client, try to update it to last version and update your firewall device with last update packages (Take).
If the problem persists, get evidences to comprove that your communication without Check Point hardware doesn't stop and some evidences of your problem and ask to your Check Point solution provider to open a case with Check Point.
We solved the problem. Technically, we never figured out exactly why it was happening, but UDP packets were getting received by the VPN server in an incorrect order, or sometimes not at all. The firewall didn't give us any indication that it was doing this, so as best we can figure it was an unlogged side-effect of CheckPoint's multiple layers of threat protection.
We switched over to using OpenVPN over TCP instead of UDP, and that seems to have solved the problem. Hopefully we don't suffer any adverse effects from that in the long-term!

PHP on Linux randomly fails to connect to Microsoft SQL Server 2005

(Not a Linux guru!) At work we have for the past month had a serious issue that we haven't been able to solve. From a server running Ubuntu-Linux we are using PHP to connect to a server running Microsoft SQL Server 2005. This has been working without problems for a long time. At the start of February 2013 we moved the SQL Server machine into the same core network as the Linux-machine, which involved changing IP-address on the Windows-server running SQL Server 2005.
After this operation we've had issues connecting to the SQL Server from this particular Linux-machine. Maybe one out of 1000 connections fails with the following error message:
PHP Warning: mssql_connect(): Unable to connect to server
I'm not aware of any other changes to either of these two servers. We've tried to look at 'everything'.
FreeTDS
php.ini adjustments
IP-address in SQL Server Configuration Manager
Unlimited number of concurrent connections in SQL Server
Network and firewall issues (No packet loss during 24 hours)
Any suggestions to how we can pursue error searching for this problem? Any more info anyone would like to know about this setup? It's kinda serious for us since many of our cronjobs fail to execute normally due to this random connection problem.
Rgds,
Sven David, Norway
Very difficult to diagnose from an external perspective, however, it feels like a networking issue rather than php/sql config. Presumably, because it's intermittent, it's not mssql functions/extension. Very little is truly random!
Perhaps approach this by writing a script that monitors the servers (both hosts) vital stats - like a heartbeat: IPs, DNS, DHCP?, requests etc and setting it to record anomalies/alert you when any element changes on either host or connect requests fail...
Probably worth posting on other SE sites too - not just Stackoverflow.

'Database Error: Unable to connect to the database:Could not connect to MySQL' in Joomla

I am using joomla 1.5, and my site was running fine, but suddenly couple of days back I got the error Database Error: Unable to connect to the database:Could not connect to MySQL
Its not always, the error is coming. Sometimes the error is coming, and sometimes not. If I have wrong database connection values, then why, is the site coming perfect sometimes. I double checked my database connection values, and are completely fine.
Try http://www.scholarsmarket.com/beta/top-ranked-students this link. Refresh this couple of times. You will get the problem
I am stuck with this error. Can't get out of this.
It a very common issue to tell exact reason, I think you should start from asking your hosting support about any limitations e.g. Database connections?
then take a look at the logs and statistics - probably you site suddenly got too much visitors at that time?
If this error seems to pop up 'randomly' it's usually because either persistent connections are used (or another reason why the connection goes into sleep mode for some time). Persistent connections are generally not a good idea on medium- to high-traffic sites, since it clogs up your database with 'sleeping' connections. Once those connections hit the maximum connection account for your database user, the MySQL server will reject any new connections and throw the error you are seeing.
So, in order to fix this problem, make sure your db config is not set to use persistent connections. You can also verify if this is the problem by running this query on your database (given that you have the proper permissions to do so):
SHOW PROCESSLIST;

SQL Server Access Question

I have a machine that is only able to connect to a 2008 SQL server sporadically. I created a monitoring script that I have automated to attempt a connection (via sqlsrv driver and php) every 15 mins. This script has ran fine for the last two weeks but recently it has been reporting a SQL server going down. On extensive investigation I am able to connect to it from every other machine consistently except for the machine automating the monitoring script. This script also connects to two other SQL servers (both are sql server 2005) without any problems. Here is what I have tried to resolve the failures:
1. Reset both machines (serveral times)
2. Attempted connections via several different logins countless times (including sa).
3. Deleted and recreated logins and attempted to connect.
4. Turned off windows firewall (SQL server is running on win2k8)
This is the error I get when I cant connect: http://pastebin.com/9d80mAyV
Typically it wont work for about 5 attempts (spaced 15 mins apart) then it will work for 1 attempt. Then it fails for another 5 attempts. There is no absolute consistency.
My thoughts is that it has blacklisted my client from connecting too often. Is this possible? How could I resolve this problem? Any other thoughts or suggestions?
A few more details needed:
What are you using to connect? is it an application or management studio (what version?)
Where are the servers located? i.e. are you on the same network?
You can try to increase your connection timeout. If you are connecting from management studio, then you can do this in the server registration properties.
Alternatively, you can setup sql monitoring on the server itself, and it will email you when it goes down.

Categories