473,809 Members | 2,633 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1221
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
15466
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 shows all current backups, and restores the selected one with one click...
4
4428
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 don't wish to rely on the web host doing so. I am using the "dbsender.php" script, which is written for this exact purpose (available at hotscripts.com). If I execute the script via my browser, the database is emailed to me in a 'gzip' format, which...
0
2291
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 that passes these commands remotely through ssh: (1) ssh dbsys-dc "sudo /etc/init.d/mysql stop" (2) ssh dbsys-dc "sudo tar
0
1871
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 2.14 Host B: RedHat 7.3, MySQL 4.0.12 (default config)
4
12728
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 though the file may be too big! When I try to do it via command line: mysql -u root --host=localhost printing < ./printing.txt It eventually errors out with a "syntax error on line X" and only about
2
1216
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 = 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
0
1900
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 server following command: CREATE DATABASE dbname DEFAULT CHARACTER SET latin5 COLLATE
13
2314
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 internet connection goes down. It occurs to me that a local MySQL instance should definitely be in each store to continue work if the net is down for any reason. But, what is the best way to synchronize/share data among all of the stores? ...
1
5290
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 #./configure it goes through all of the preparing tables and starting mysqlServer and daemon, but than immediaetly says "mysql ended" -- I try to do #make right after anyway, but I get the error "No targets specified and no makefile found" -- Any...
2
1163
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) i need to change the server,so i made a backup of mysql database and put it on the new server,i created a mysql user to handle connections and i also changed the ODBC data source on the work machine with the new IP adress of server. what is...
0
9721
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
10640
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10376
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...
1
10387
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9200
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
7662
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
6881
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();...
0
5689
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3015
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.