Tag Archive for 'PHP'

MySQL Error/Warning: Too Many Connections

This post is to help server administrators who are managing MySQL servers. If you run into users complaining about error regarding too many connections to MySQL, do check the script that runs and make sure that connections are closed.

For example if you open a connection in php using:

$mysqli = new MySQLI(’localhost’,'root’,'password’,'dBName’);

At the end of the script, do remember to close the connection by calling:

mysqli_close($mysqli);

To verify that things are working, SSH into your system,

1) go into MySQL command line by typing something like mysqld -u root -p
2) type in “show processlist;
3) take note of the processes already running
4) Run the php (or .net or whichever script)
5) type in “show processlist;” again a while after the script has finished executing
6) If you see new processes being in Sleep status then the script is not closing the connections properly (unless this is a deliberate action by the developer to re-use a connection, but this usually should not happen)
7) You can manually kill the process by typing “kill <process id>;” (You can see the process id in the process list table

So if the script is not closing connections, the script should be checked to ensure that they are closed and run through the test above again. This will assist in the server’s performance as well.

Note: The default max_connections, which govern the maximum number of connections to the MySQL server instance is 100, you can increase this, but it is not a good solution compared to the above which addresses the root of the issue. MySQL has a suggestion that dynamically increases the max_connections which works as well but it has to be dependent on the scenario you are facing.

EMS SQL Manager Lite

I had been working with this wonderful piece of software and had no problems with it until today when I realise that the software maintains a consistent connection to MySQL server until you hit the commit transactions button. This means any queries from somewhere else like PHP will get hung up and timeout, so if you are wondering why things are not moving, do check this piece out.

Installing PHP5 on IIS7 in Windows Vista

Server Crash
For the past week or so, the server hosting the blog crashed bad and had to be sent in for repairs and the recovery process was a very tedious one. Kudos to the people over at 8toinfinity for working throughout the week to bring the server back into shape. The fortunate thing was that we didn’t lose data thanks to RAID mirroring and everything was more or less preserved.

Setting up PHP5 on IIS7 in Vista – My journey of exploration and discoveries
In the meantime I had attempted to set up PHP on IIS7 on my local machine to do some testing and ran into some issues with the latest version of PHP 5.25 Win32 installer while setting it up with IIS7 on Windows Vista. Apparently after using the installer, IIS7 on Windows Vista actually does not get modified properly to support PHP out of the box. A bit of disappointment there but I proceeded to remove PHP5 via the uninstaller and downloaded the zip package to do manual set up. That was where the problems set in. I kept getting an error where my IIS Worker Process kept crashing resulting in the Default App Pool to get shut off after repeated failures to launch a dll or exe. (Take note that im setting up FastCGI for PHP on IIS7).

Somehow after removal of PHP5 via the uninstaller and using the zipped version, PHP was still trying to use the php5isapi module although I had removed it from IIS completely (or so i thought). Here is the error you might see although php5isapi had been seemingly removed: (IMPORTANT: The following are NOT steps to be followed for a clean installation of PHP on IIS7)

Here is what you need to check:

Start >Run > “cmd” (Bring up your command prompt on Vista)

Navigate to your <Windows Directory>\System32\inetsrv folder (e.g. C:\windows\system32\inetsrv)

Then execute the following command: “appcmd list config -section:globalmodules

You should see an XML list being shown that shows the installed modules in your IIS.

Look for this:

<add name=”php5isapi” image=”C:\php\php5isapi.dll” />

If it exists, it means php5 was NOT uninstalled properly. So we need to remove this entry before FastCGI will work.

Use the following commands:
C:\Windows\System32\inetsrv>appcmd set config -section:globalmodules /-[name='php5isapi']

If successful, you will get the following message:
Applied configuration changes to section “system.webServer/globalModules” for “MACHINE/WEBROOT/APPHOST” at configuration commit path “MACHINE/WEBROOT/APPHOST”

Try listing the modules again and the php5isapi node should be removed.
C:\Windows\System32\inetsrv>appcmd list config -section:globalmodules

With all these done, you can then proceed to set up FastCGI for PHP on IIS7 by

Running: fcgisetup.exe /install /add c:\php\php-cgi.exe php

from the directory on which you downloaded the FastCGI package.

This should set up PHP FastCGI on IIS7 automatically.

If your app pool was stopped (e.g. defaultAppPool), simply restart it in IIS7 and try to load the php page again. It should work.

You should see the following handler mappings in IIS7:

You should see that php-iisfgi is in the list, this means the PHP FastCGI module for  IIS7 is installed properly.

Lastly, just a few quick notes (this is nothing related to the above, but just a reminder just in case you were as silly as I were):

  1. For those who are unable to locate your php.ini and are about to bang your head (or have already banged your head on the desk)
    You have to add the path to your php.ini in an environmental variable called PHPRC not in the TEMP variable
  2. ISAPI and CGI support modules are not installed by default when you install IIS by just checking IIS in the program and features.
    Go back to Program and Features > Click on Turn Windows features on or off on the left sidebar and follow the following diagram making sure that ISAPI and CGI support is on. ( You can choose either depending on what PHP executable you are using )

Yep thats all I have for this post, hope this helps for  people trying to set up PHP5 using FastCGI on IIS7 :)

Cheers!