tags:

views:

25

answers:

1

I have a problem in my script that appen sometimes,usually when i leave it for some time(like 5-10 minutes)without requests i get this error:

Warning: mysqli_connect() [function.mysqli-connect]: MySQL server has gone away in FILE.php on line 30

and this is the code that gives me error is this:

$this->db=mysqli_connect('p:'.$this->db_host,$this->db_user,$this->db_pwd,$this->db_name);

The code is contained on a singleton class and i'm currently developing on windows7 with

  • Apache 2.2.11
  • MySQL 5.1.36
  • PHP 5.3.0

(i use WampServer 2.0i)but i'll obviously use linux on the final server.

Thanks.

A: 

Are you checking for errors after you connect? That might reveal the need for a reconnection. Though looking at the documentation it appears there's no way to force mysqli to create a new connection.

You could use mysqli_ping() to check the server before each call to the database but that's kind of a pain if you have a bunch.

The other thing to do if you admin the MySQL server or are on good terms with the person who does, is to increase the idle timeout on the server itself.

Personally IMHO, persistent connections are buggy in PHP and unless you have a very high-traffic site the increase in speed isn't enough to make it worth the trouble.

Cfreak
Mysqli should handle a lot better the persistent connections,the web server is a local TESTING windows server so it's not mean to have huge performance or be error proof.I need great mysql performance because i use mysql sessions and it's for an hight performance framework.I didn't check for mysql connection error because it's something that shouldn't happen,i want only know if it's for a server error(because its' a test crappy server),because some code errors or because of a php bug.
Plokko
Do you have high-traffic? Because if you're getting less than a million people a month you're not going to notice a performance difference.
Cfreak
You should always check for errors even if it is a testing server. You can't know what type of error it is if you aren't checking for them. It's silly to not check because they "shouldn't happen". All languages have bugs, to not check for them is terrible practice.
Cfreak
i know but i need a tip to know whare to search for a fix.Anyway i'm using JMeter to benchmark my performance in some hightly multithreaded pages and i don't get errors even with 100 thread opening 100 pages,i don't know why it created problems and it looks like i could make querys normally even after that error,i'll look into it.
Plokko