TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 07-27-2009, 09:02 AM   #1 (permalink)
The Contributor
 
Join Date: Mar 2009
Posts: 49
Thanks: 0
TheOnly92 is on a distinguished road
Default Maintaining MySQL Connections

I am using an external MySQL database server due to the high load I receive when having MySQL running locally. Both servers are located in the same datacenter, but I found that, whenever the connection from my server to the MySQL database server goes up to about 70++, the MySQL server blocks new connections. I have been trying to use persistent connections but it still opens up a lot of connections to the database server. Is there any suggestion how to maintain the number of connections?
TheOnly92 is offline  
Reply With Quote
Old 07-27-2009, 11:44 AM   #2 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

It sounds like you're using more than the configured max_connections. See http://dev.mysql.com/doc/mysql/en/to...nnections.html
Salathe is offline  
Reply With Quote
Old 07-27-2009, 12:15 PM   #3 (permalink)
The Acquainted
 
JaoudeStudios's Avatar
 
Join Date: Jul 2009
Location: Surrey
Posts: 105
Thanks: 1
JaoudeStudios is on a distinguished road
Default

MySQL by default is usually set to 100 connections, so you will need to up this. Persistent connections will give you more of these problems as the connection will remain open, trying using non-persistent connection if your application can handle it.
__________________
JaoudeStudios.com | JaoudeStudios.com Forum | JaoudeStudios.com Blog
OpenSource is the road ahead...!
JaoudeStudios is offline  
Reply With Quote
Old 07-27-2009, 12:27 PM   #4 (permalink)
The Contributor
 
Join Date: Mar 2009
Posts: 49
Thanks: 0
TheOnly92 is on a distinguished road
Default

But if I am to use non-persistent connections, it will definitely exceed the limit the external server set on (15 connections, not under my control). Since there will be more than 15 users going to be accessing the site at 1 time, what am I supposed to do?
TheOnly92 is offline  
Reply With Quote
Old 07-27-2009, 01:04 PM   #5 (permalink)
The Acquainted
 
JaoudeStudios's Avatar
 
Join Date: Jul 2009
Location: Surrey
Posts: 105
Thanks: 1
JaoudeStudios is on a distinguished road
Default

Quite the opposite, if you use non-persistent connections, you can have many more people on the website at once as it will use the connection then drop it, which will allow someone else to open a connection.

15 persistent connections will only allow 15 users.

15 non-persistent connections will allow many more than 15 users.

NB: Glad I am not using my ruby on rails app on that connection, it pools 5 connections per user for speed :). So I would only be allowed 3 users :s
__________________
JaoudeStudios.com | JaoudeStudios.com Forum | JaoudeStudios.com Blog
OpenSource is the road ahead...!
JaoudeStudios is offline  
Reply With Quote
Old 07-27-2009, 01:06 PM   #6 (permalink)
The Contributor
 
Join Date: Mar 2009
Posts: 49
Thanks: 0
TheOnly92 is on a distinguished road
Default

Ok, I will be using non-persistent connection for a while, then I will report back what's the situation.

EDIT: I forgot to mention, my script uses Ajax call every single second from each user to get some stats, it won't be accessing the database but it certainly do connect to the database since I include the whole header together with the part connecting to the database. In this case, does any suggestion change?
TheOnly92 is offline  
Reply With Quote
Old 07-27-2009, 01:28 PM   #7 (permalink)
The Contributor
 
Join Date: Mar 2009
Posts: 49
Thanks: 0
TheOnly92 is on a distinguished road
Default

Ok, it doesn't work at all. It connects more than 50 connections at a time, are there anymore solutions? I tried setting max connection in php.ini but still didn't work.
TheOnly92 is offline  
Reply With Quote
Old 07-27-2009, 02:13 PM   #8 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Default

LINK1

LINK2
Take a look at does links should be some more, information.
on the problem you are having.

and also you could try to google, "setting max connection + mysql" it did give me some info :)


-Cf
codefreek is offline  
Reply With Quote
Old 07-27-2009, 02:29 PM   #9 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

Quote:
Originally Posted by TheOnly92 View Post
Ok, it doesn't work at all. It connects more than 50 connections at a time, are there anymore solutions? I tried setting max connection in php.ini but still didn't work.
Did you edit your mysql config (typically called my.cnf in /etc), you can't edit mysql server settings via php.ini

you will need to add something like:
Code:
[mysqld]
set-variable = max_connections=200
of course you will need to restart mysql for this change to be effective.

You could also set it to 0, then mysql wont limit it at all, however this probably isn't a good idea.
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
Old 07-28-2009, 08:00 AM   #10 (permalink)
The Contributor
 
Join Date: Mar 2009
Posts: 49
Thanks: 0
TheOnly92 is on a distinguished road
Default

First, I wish to state that the MySQL server is out of my control, I can't make any changes to it. Second, I hope to solve this problem by PHP.

By the way, please note that the external MySQL server is a shared hosting server. It blocks connection when the connection number reaches 50.
TheOnly92 is offline  
Reply With Quote
Old 07-28-2009, 08:59 AM   #11 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

Then I doubt you will be able to do anything about it, unfortunately. To my knowlege you cannot set MySQL server variables via PHP.
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
Old 07-28-2009, 10:27 AM   #12 (permalink)
The Acquainted
 
JaoudeStudios's Avatar
 
Join Date: Jul 2009
Location: Surrey
Posts: 105
Thanks: 1
JaoudeStudios is on a distinguished road
Default

Quote:
Originally Posted by TheOnly92 View Post
First, I wish to state that the MySQL server is out of my control, I can't make any changes to it. Second, I hope to solve this problem by PHP.

By the way, please note that the external MySQL server is a shared hosting server. It blocks connection when the connection number reaches 50.
Unfortunately, you are s**t out of luck, you can not override this with php! As it would be a security risk. You could try and be clever by queuing the connections - but it wouldnt be easy.
__________________
JaoudeStudios.com | JaoudeStudios.com Forum | JaoudeStudios.com Blog
OpenSource is the road ahead...!
JaoudeStudios is offline  
Reply With Quote
Old 07-28-2009, 10:31 AM   #13 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

Quote:
Originally Posted by JaoudeStudios View Post
Unfortunately, you are s**t out of luck, you can not override this with php! As it would be a security risk. You could try and be clever by queuing the connections - but it wouldnt be easy.
Indeed! This is where shared hosting becomes inadequate you will have to think about getting your own server (be it a dedicated box or even a VPS) if you want to tweak server settings.
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
Old 07-28-2009, 11:47 AM   #14 (permalink)
The Contributor
 
Join Date: Mar 2009
Posts: 49
Thanks: 0
TheOnly92 is on a distinguished road
Default

Some budget problems prevent me to get a vps...
TheOnly92 is offline  
Reply With Quote
Old 07-28-2009, 12:19 PM   #15 (permalink)
The Contributor
 
Join Date: Mar 2009
Posts: 49
Thanks: 0
TheOnly92 is on a distinguished road
Default

Ok, I will be using iptables method to solve this problem anyway. Thanks for all the help.
TheOnly92 is offline  
Reply With Quote
Old 07-28-2009, 12:43 PM   #16 (permalink)
The Acquainted
 
JaoudeStudios's Avatar
 
Join Date: Jul 2009
Location: Surrey
Posts: 105
Thanks: 1
JaoudeStudios is on a distinguished road
Default

Quote:
Originally Posted by TheOnly92 View Post
Some budget problems prevent me to get a vps...
Check out rapidswitch.com, I remember their VPS being very cheap! I have a Dedicated box with them and so far they are pretty good.
__________________
JaoudeStudios.com | JaoudeStudios.com Forum | JaoudeStudios.com Blog
OpenSource is the road ahead...!
JaoudeStudios is offline  
Reply With Quote
The Following User Says Thank You to JaoudeStudios For This Useful Post:
sketchMedia (07-28-2009)
Old 07-28-2009, 12:59 PM   #17 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

They are quite reasonable, the dedi's arnt too bad either.
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Using a MySQL class Andrew General 12 07-14-2009 03:49 PM
Multiple mysql connections doesn't seem to work :S SpYkE112 Advanced PHP Programming 6 06-10-2008 12:16 PM
MySQL Sell Up Alan @ CIT The Lounge 12 01-17-2008 05:46 PM
Error in connecting to MySQL via PHP EyeDentify MySQL & Databases 0 01-03-2008 01:06 PM
Notepage like application to open large MySQL files Wildhoney General 6 12-07-2007 02:18 PM


All times are GMT. The time now is 12:47 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design