Solved

PHP 'max_user_connections'  error when using mysql_pconnect

Posted on 2006-11-09
4
667 Views
Last Modified: 2013-12-12
I am getting the following 2 errors randomly when accessing dynamic areas of my client's site... repeatedly refreshing the page eventualy gets my request to go through:

Warning: mysql_pconnect(): User initiate_admin has already more than 'max_user_connections' active connections in /hsphere/local/home/***/***.com/Connections/Cart.php on line 9

Fatal error: User initiate_admin has already more than 'max_user_connections' active connections in /hsphere/local/home/***/***.com/Connections/Cart.php on line 9

My host says I have max_user_connections=20. However I am using mysql_pconnect for my connect string. I am the only one on the page right now while I'm developing it. How could I have used all 20 persistant connections? If I somehow did is there any way to close them all?
0
Comment
Question by:feign3
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 35

Expert Comment

by:Raynard7
ID: 17912552
Hi,

The max_user_connections can now be set for both the user and the machine level

http://dev.mysql.com/doc/refman/5.0/en/user-resources.html indicates how to view what permissions that you have for the actual user

and if you use show process list you can see all the currently active connections on your server (if you have the appropriate permissions) you could then kill the threads that you do not want open

http://dev.mysql.com/doc/refman/5.0/en/kill.html

I suspect that if you are connecting with something other than php as well - and you have connection pooling enabled then you could have more than 20 persistant connections - same thing would happen with a .net application where garbage collection was not working

generally with php the connection is closed the moment the page  stops loading to this is unlikley to be the problem - however it is probably a setting at th euser leve.
0
 
LVL 18

Accepted Solution

by:
Mark Gilbert earned 50 total points
ID: 17929174
I would recommend against using pconnect.  Pconnect is a connection that uses persistant connections.  If a user is doing a select query, followed by an update, followed by an insert, and delete, that's 4 connections already taken up, by 1 user.  Change your connection to use mysql_connect instead and you will find that your user connections will drop considerably.  Pconnect shouldn't be used unless tables are being specifically locked for update/insert queries, and is very heavy on the system.

Hope this helps.
0
 
LVL 18

Expert Comment

by:Mark Gilbert
ID: 17929184
For more information about mysql_pconnect(); see:

http://uk2.php.net/manual/en/function.mysql-pconnect.php

and for more information about mysql_connect(); see:

http://uk2.php.net/manual/en/function.mysql-connect.php
0
 
LVL 18

Expert Comment

by:Mark Gilbert
ID: 17929191
oh, Just a clarification in case you don't look at the links provided:

"mysql_pconnect() acts very much like mysql_connect() with two major differences.

First, when connecting, the function would first try to find a (persistent) link that's already open with the same host, username and password. If one is found, an identifier for it will be returned instead of opening a new connection.

Second, the connection to the SQL server will not be closed when the execution of the script ends. Instead, the link will remain open for future use (mysql_close() will not close links established by mysql_pconnect()).

This type of link is therefore called 'persistent'. ".

Hope this helps.
0

Featured Post

Are You Using the Best Web Development Editor?

The worlds of web hosting and web development are constantly evolving. Every year we see design trends change, coding standards adapt and new frameworks/CMS created. With such a quick pace of change it’s easy to get lost trying to keep up.

See if your editor made the list.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question