473,624 Members | 2,191 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to escape mysql_connect() DNS caching?

Hello people,

There is a problem is that mysql_connect() somehow caches last sessions
IP and is not using the one which you put into host place.

Has anyone made mysql_connect() from php to multiple SQL servers so
that script tries to connect to resolved IPs until it finds one that
works?

I have set up DNS so that on request sql.example.com it returns two
IPs (rotating on each request).
When I see output of script below I see that php function
gethostbyname() does DNS requests in for() cycle and does return sql
nodes IP in rotated manner, but from tcpdump I see, that
mysql_connect() is using just one IP to connect to port 3306.

Is there some way to flush the mysql_connect() dns cache?
$dbaze="abc";
for($cnt=1;$cnt <=6;$cnt++){
$ip=gethostbyna me('sql.example .com');
echo $ip."</br>";
$db =mysql_connect( $ip, "user", "pwd",1);
if($db)break;
}
if(!$db){
die("Error connecting to the Server");
exit();}
I think this is the problem in mysql library used by php, so I tried to
drill down there and found comment beolw in developers page. I am not
wery well in C so I am
not sure where to put this piece of code so that recompiled mysql and
php(or just php)
would contain correct mysql_connect() function that does connect to IP
which is given.

This problem is very strange mostly because right now mysql is
advertising its cluster - so
connection to multiple SQLs is just natural to be really "no single
point of failure".

Can anyone suggest a solloution to this?
Txh in advance!

versions:
OS=FreeBSD 6.1
mysql=5.0.24(fr om source)
php=5.1.5 (from source)

----
From: http://dev.mysql.com/doc/refman/5.0/...l-connect.html
Posted by Andrew Donkin on March 4 2005 2:23am [Delete] [Edit]

If you have configured your DNS to return a list of MySQL servers, and
you want your client
to work through that list until it finds one that works,
you can put real_connect inside a getaddrinfo() loop.
I wish the client library did it by itself:

struct addrinfo *addr, *addrlist;
struct addrinfo hints = {0, PF_UNSPEC, SOCK_STREAM,
0, 0, 0, 0, 0};

int gai_result = getaddrinfo(hos t, 0, &hints, &addrlist);
if (gai_result) bomb(Unknown host);

for (addr = addrlist; addr; addr = addr->ai_next) {
#define IPNAMELEN 20
char ipnamebuff[IPNAMELEN];
const char *ipname = inet_ntop(((str uct sockaddr_in *) addr->ai_addr)
->sin_family,
(void *)&((struct sockaddr_in *) addr->ai_addr) ->sin_addr,
ipnamebuff, IPNAMELEN-1);

mysql_real_conn ect(mysql, ipname, user, pass, database, ...);
}
---

Aug 19 '06 #1
1 4359
Hello,

found the problem:
1)PHP didn't read correct config file - so mysql.connect_t imeout was
not correct
2)as I use FreeBSD jails - tcpdump didn't show packets between jails on
same machine because they do not cross interface..

Problem was between screen and chair..:)

Aug 22 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1851
by: LRW | last post by:
I'm working on some scripts someone else made, and it's littered with repetitive mysql_connect's and mysql_select_db's. For example: // MAKE SURE IT IS A VALID PRODUCT $connection2 = mysql_connect("localhost", "root") or die ("Couldn't connect to the server."); $db2 = mysql_select_db("priceretail", $connection2) or die ("Couldn't select database."); $sql2 = "SELECT dbname FROM productlist WHERE ((accountid = 'printingautomation') OR...
2
2100
by: Bilal | last post by:
Hi, Does anyone know the escape character for & and # like in : Update GDO_INFO_ER set V_COMMENTAIRE='B&A' where V_USERMODIFICATION='bilal123' or Update GDO_INFO_ER set V_COMMENTAIRE='B#A' where V_USERMODIFICATION='bilal123' I would like to insert & and # literally in the table. I appreciate any help or suggestion. Thanks oyu Bils
10
5103
by: Alvaro G Vicario | last post by:
I need that my script retrieves data from two different databases so I use mysql_connect() to open two connections. I have only one server, user and password, just two different databases. Simplified, it'd be: $con1=mysql_connect($server, $user, $pass); mysql_select_db($database1, $con1); $res1=mysql_query($sql1, $con1); $con2=mysql_connect($server, $user, $pass);
4
5758
by: Andrew Clark | last post by:
Hello, I am having trouble connecting to my server with mysql_connect(). I can connect via the command line on the server and with phpMyAdmin over our network, but not though mysql_connect(). This is my script: <?php $host = '192.168.100.5'; $user = 'root'; $pass = <password>;
2
2831
by: Sugapablo | last post by:
I have a small test script connecting to a MySQL database. It seems to work, unless I try to use the resource link identifier returned by mysql_connect(); This works and returns all the rows in the table: <?php include("../config.php"); $dbi = mysql_connect($dbhost,$dbuname,$dbpass);
19
8098
by: Michael | last post by:
Hi, I'm trying to do something which should be very simple - connect to the MySQL database. Here is the call, followed by the error msg. $conn = mysql_connect("localhost", "root", ""); Warning: mysql_connect(): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (13) in /var/www/html/buildhw.php on line 13
7
5407
by: avenpace | last post by:
Hi, I got error when using mysql_connect function in my php script. If i set the db host to localhost, it give me that error altough all the user and password that I wrote is true(I can login using that username/passwd using mysql console), but when I change the db host into 127.0.0.1 mysql_connect will work. Beside of that I can't make my php script to do I/O operation on dir/file in the apache /var/www though the permision already own...
6
3355
by: GD | last post by:
Hi All, I've got MySQL 5.0.21 running on Windows Server 2003, and php running on Apache on a Linux box (Fedora Core 4). Previously when the pages were running on an IIS server the connection was succesful, now I get: Can't connect to MySQL server on 'SERVER' (13)
7
2843
by: criveraf | last post by:
Hi there, I wasn't sure where to put this question, since it deals with both PHP and MySQL. I apologize if this is not the correct forum for this. I am working with a simple PHP application using MySQL at the data layer. This is on a Windows XP machine, using IIS 6.0, MySQL 5.0, PHP 5. The problem I am having is that a call to mysql_connect is not working, it is not doing anything at all. I'm not getting any error messages, or...
0
8234
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8172
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8620
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8474
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7158
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6110
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5563
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2605
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1482
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.