473,402 Members | 2,072 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Mysql Backup Connection in PHP

I notice with PHP if a connection cannot be established to a mysql
server with mysql_connect() PHP will timeout and never try the backup
server. In this example:

$db = mysql_connect('db1.local.net', 'username', 'password');
if (!$db) {
$db = mysql_connect('db2.local.net', 'username', 'password');
}

This works great and connects to the 2nd database if the 1st one
rejects the connection completely; however, if the 1st db is under high
load and doesn't respond for 10+ seconds it never jumps to the 2nd one.
Curious if there's a better way to accomplish this. If the 1st db
doesn't respond in 1 second max I'd like to hop to the 2nd one.

Does the newer mysqli_connect handle this better, anyone know?

Apr 12 '06 #1
2 1193
Don't know about mysqli_connect() but you could use fsockopen() and set
a short timeout, close the connection and then reconnect with
mysql_connect();

I would hope there was a tidier solution that this though. Perhaps load
balancing on the backup server, in relation to how much it can handle?

Apr 12 '06 #2
Another issue I'm trying to overcome is locking issues. We do
dual-master replication, and in the event a table is locked on db1, it
should still be readable on db2. It would be great to have a way to
timeout a connection if no response rcv'd in say.. 2 seconds for it to
kick to the 2nd server.

Apr 15 '06 #3

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

Similar topics

3
by: James | last post by:
HI, I'm looking for a script that will allow users/admins to have a one click backup solution for a MYSQL Database.. 'BACK DATABASE' button, click and its done... The a restore option, that...
4
by: Neil | last post by:
Hi, I hope this question isn't too far off topic....I'm almost at my wits end trying to figure this out. I have a Mysql database and I wish to automate the backup of the database because I...
0
by: Duane Winner | last post by:
Hello all - I'm having a small problem with the mysql startup script that ships with MySQL-3.23.56-1. I'm running on RedHat Linux. It works fine, but I have a backup server that runs a script...
0
by: Cheng-Dar Yang | last post by:
Hello, I am not sure if this problem is due to Bugzilla or MySQL... But, some MySQL gurus here may be able to confirm if this is proper behavior of MySQL. Setup: Host A: RedHat 7.1, Bugzilla...
4
by: news | last post by:
Our production database in an exported textfil runs about 60 MB. Compressed that's about 9 MB. I'm trying to import the export into another machine running FC3 and mySQL 11.18, and it appears as...
2
by: Locu | last post by:
I notice with PHP if a connection cannot be established to a mysql server with mysql_connect() PHP will timeout and never try the backup server. In this example: $db =...
0
by: newman | last post by:
Dear all, I have mysql 4.1.11 on my current server, i need my database restore another server.. (another server mysql version is 4.1.11 same.) And now... I just created new my database to new...
13
by: Jim Hubbard | last post by:
I have a client that desires a new application for use at several stores in different cities. He wants "real time" access to all store data and the ability to continue to run locally even if the...
1
by: PowerLifter1450 | last post by:
I've been having a very rough time installinig mySQL on Linux. I have been following the instructions form here: http://www.hostlibrary.com/installing_apache_mysql_php_on_linux Everytime I get to...
2
juve11
by: juve11 | last post by:
hello, i have an app (WICH IS NOT MINE so i dont have source code) installed on 5 computers and a mysql server. this app works with two tables from a mysql database (lets say table_A and table_B)...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
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,...

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.