I have tried 3 different server machines with Windows 2003 server software.

I put web edition on 2 of them, and Enterprise on the third, all 3 machines when I (copied below) it should in theory run forever since the script opens connection queries, prints then closes that connection. However after exactly 3970 connections are opened it ALWAYS says "connection problem". all 3 machines do this. Interestingly, the windows 2000 machine does NOT do this. It goes on forever and ever and ever, however on heavily loaded machines it gives "page cannot be displayed" at random. This is all very frustrating! Any help is greatly appreciated!

<?
$intf=0;
while(empty($intx ))
{

$chandle = mysqli_connect("DB", "UNAME", "PWORD");
mysqli_select_db($chandle, "DB1") or die ("connection problem.");

$query="select count(*) FROM table1";
$result=mysqli_query($chandle,$query);
mysqli_close($chandle);

$temprow=mysqli_fetch_row($result);
$count=$temprow['0'];

echo "$intf $count <br>";
$intf++;
}
?>

    forgot to mention the versions we're using. Tried ALL versions of apache after 4.0 and all PHP's 5.0 and higher (using 5.1+ now). All give exact same results

      Why do you keep opening and closing the connection? Just open it, and run as many queries on that connection as you need to.

        I'm testing how the system is able to handle it. I have a production websit running using this sytem, and I kept randomly getting DB connection errors while using it. It took me a long time to figure out that it was the OS that was having these connection issues (during peak times especially), and not the DB being maxed out.

          What you're likely testing here is the mysqli interface, which is kind of new anyway. It's probably got a leak somewhere and isn't freeing resources.

          Or it could be a php bug, that php is not freeing resources.

          What you're not testing is you mysql server. to do that, try writing a shell script that calls a short php script like yours (that only connects, runs the one query and disconnects) over and over FROM the shell script.

          Note that your production site probably isn't using the same php child process to open and close a database connection several thousand times. Unless you're running lighttpd.

            OK, I just tested the same basic script on my linux box. Apart from running on Linux, I'm also using the standard mysql libs, not the mysqli libs. That's what fedora core 4 comes with. And I don't really feel like torturing myself to build the mysqli connect libs / php from source to test them.

            I was able to open the connection 100,000 times, run a simple query, and close it.

            So, whatever's happening here is either mysqli's fault or window's fault, but it doesn't look like a problem with the core of php itself.

            Still, this isn't likely to be a real valid test unless your scripts actually open and close the connection thousands of times with one call.

              right i'm not experiencing this problem on any platform than windows 2003 server. that's my problem. It works perfectly on windows 2000, but that raises some other problems in terms of maximum ram that can be utilized and so on.

                You might want to try using a simple benchmarking tool like ab from apache to load the server from the front end. Write a simple script that opens the db, selects something simple, and closes the connection.

                Then, use ab (or jmeter if you'd like a gui tool) to beat on the server from the front end and see how it behaves.

                  ab is part of the apache main tarball. It's a standard part of the package, at least on Unix compiles / packages.

                  If you've got apache installed on a box, see if it's there already.

                  Oh, and ab stands for either "Apache Bench" or ABuse, depending on which descriptions you read... 😃

                    hmm I dont see it on the windows installation.

                      3 months later

                      Hi,

                      I experiment the same problem:
                      - mysqli_connect return an error after some connect/deconnect actions

                      It is really simple to test:
                      just make a loop like this one

                      for ($i = 0; $i < 99999; $i+) {
                      mysqli_connect(...)

                      mysqli_close(...)

                      }

                      And you will see the problem on Windows 2003 and not on windows 2000

                      If you use the mysql_pconnect fonction of the extension 'mysql_extension', it works well too on windows 2003

                      Have you an idea of what is happening ?
                      Do we need to forget the improved extension of mysql ?

                      It is stange that I cannot find topics on the internet about this problem.

                      Thaks for your help

                      Leinad

                        Since it's looking like a Windows 2003-specific issue, I'm moving this thread to the Windows forum.

                          6 days later

                          On the Windows 2k3 box, have you tried going into the registry and navigating to this key:

                          HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\HTTP\Parameters

                          Do you see an entry called "MaxConnections" ? If not, try creating a new DWORD value and call it such. Give it a higher number, like 8000 or something.

                            There is no variable for maxconnections, and creating one does not affect the problem. As Leinad described above, thats exactly how you produce the problem and I got around it by downgrading all the software to use mysql_pconnect instead of mysqli_connect. it lowered performance, but that threshold of 3970 connections is not there using these functions. I think its some mysqli memory leak that has not yet been addressed by PHP.

                              I agree with you JwwTaker, The issue is not the variable maxconnections. I will do more tests on this, but at the moment the only way to solve the problem is to return to the msql_pconnect. But for me it seems that performances are best with mysql_pconnect. I precise that my MySql server is separated from the web server.

                              I am not sure that this a memory leak, because I am not able to reproduce it with Windows 2000, but I suspect that Windows 2003 does not release ressources immediately, because if I put a delay between queries, the problem finish to decrease or disapear the more the delay is long

                              (Sorry for my poor english, I am french !)

                                One thing you might try is posting your problem as well as all that we've discovered here in a bug report at http://bugs.php.net

                                You might even want to search the bug database first to see if this problem or a similar one has already been discussed before.

                                  Write a Reply...