Re: question - support

From: Date: Sat, 10 May 2003 22:05:12 +0000
Subject: Re: question - support
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-147149@lists.php.net to get a copy of this message
Fabricio Orerreug wrote: > this my error > Warning: Supplied argument is not a valid MySQL-Link resource in ..... > > it seems to be that my site is generating more visits which my server can handle. and > everytime i pass a couple of thousand of visits a day i get this error. > and the only way of fixing it is restarting the mysql daemon. my question is there anyway i > can restart this daemon via php so i wont have to keep on doing this manually? please help. Things you need to figure out: #1. Are you using mysql_connect() or mysql_pconnect()? If the latter, odds are really good that you've got *MORE* Apache children than available MySQL connections. Don't do that. The number of Apache children is set in 'httpd.conf' which is probably in /usr/local/apache/conf/httpd.conf, unless it's in /etc/httpd.conf or in some other location, depending on who installed Apache and how they felt like installing it. :-v Basically, when you use mysql_pconnect(), EACH Apache child "eats" one (1) MySQL connection. You can increase the limit in /etc/my.cnf (?) or whatever configuration file it is that MySQL uses. You may not have followed the detailed install instructions, and thus may not HAVE an /etc/my.cnf file yet, but you *SHOULD*, so create one now if you don't have one. And test something you can set in it after stopping/starting MySQL to be sure it's taking effect, since MySQL could have been COMPILED to be looking somewhere else for my.cnf, depending on who compiled it and how they felt at the time. :-v You actually want a few "extra" MySQL connections available, so that if you have a run-away application, you can still pop into 'mysql' (and/or 'mysqladmin') from the shell and start killing off MySQL. If all the available MySQL connections are chewed up by Apache, you are SOL. #2 Once you have *MORE* MySQL connections available (in my.cnf) than Apache children (in httpd.conf), if you *STILL* have this problem... Now things get tricky. You have to figure out whether: #2A Is MySQL simply not shutting down connections when it should? #2B Is PHP somehow keeping them open when it shouldn't? #2C Are you actually getting >1,000 queries/hits concurrently? If it's A, upgrade MySQL. If it's B, upgrade PHP. If in doubt, upgrade MySQL and PHP and pray. :-^ If it's C, then you then have to figure out if maybe you just plain don't have enough hardware or if you have OS limits stopping you somewhere. It could be a lack of RAM, lack of hard drive space, limit on the number of open files MySQL is allowed to have (?) lack of CPU (I guess...???) Odds are really good, you're looking at #1 -- I went into #2 only just in case. Oh yeah, I never did answer your actual question "Can I get PHP to restart the MySQL demon?" The answer is: "Yes, but you don't want to do that, it would be really tricky to do it securely, you could just do it with cron and not involve PHP at all, and it's not the right solution to your problem in the first place." Fix your real problem: don't slap a band-aid on a sucking chest wound.

« previous php.general (#147149) next »