Navigate / search

MySQL Connection Response Slow on Windows 2008 / 2012

One of the reasons why a PHP / MySQL combo seems so “slow” with regards to response times when moving from Windows 2003 (IIS6) to Windows 7/2008 (IIS7) / 2012 (IIS8), is the way many scripts connect to MySQL and having IPv6 enabled by default.

Many server installations leave WordPress or other PHP script installs to default to “localhost” when connecting to MySQL. Windows 7, 2008, 2012 have an issue with resolving localhost when IPv6 is enabled. With iishacks.com, the initial response time from MySQL goes from 600ms (using localhost) down to 70ms (using 127.0.0.1).

If your issue is initial response time, but MySQL seems to function well otherwise, your connection string may be at fault. Instead of disabling IPv6, try changing “localhost” to “127.0.0.1″  in your scripts and see if the response times improve.

Fixing an SSD Freezing on Windows 7

I recently installed a new Intel 520 series SSD in my Thinkpad W520. I didn’t notice any issues for the first few weeks until I started running 2 virtual machines at once. There was a stuttering (or freezing) every 60-90 seconds for about 10 seconds.

Taking a look at Perfmon, I found the Disk Queue to be very high – during the freezing the Max Queue was up over 3500. There is a relationship between current and average queue explained here, but a good rule of thumb is that a length of 2 per disk is reasonable. Any more than that for an extended period and there is a disk bottleneck.

 

How to stop the solid state drive from Freezing

Intel Rapid Storage Technology (RST) is the culprit, specifically LPM (Link Power Management) and DIPM (Device Initiated Power Management). Both are recommended to be enabled as they lower power consumption on SATA devices that support it, but in certain circumstances they may cause freezing, stuttering and other undesirable performance degradation.

In order to turn off LPM and DIPM, insert the text below into notepad and save the file as LPM.reg and run it or download the file and unzip. The following disables LPM/DIPM for all SATA ports on a machine. If you only want to disable for a specific port, delete the other keys below. This will work for any SSD experiencing stuttering or freezing while using Intel RST drivers only (MS Default AHCI not included). Make sure you restart after you’ve run the registry file.

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\iaStor\Parameters\Port0]

“LPM”=dword:00000000
“LPMDSTATE”=dword:00000000
“DIPM”=dword:00000000

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\iaStor\Parameters\Port1]

“LPM”=dword:00000000
“LPMDSTATE”=dword:00000000
“DIPM”=dword:00000000

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\iaStor\Parameters\Port2]

“LPM”=dword:00000000
“LPMDSTATE”=dword:00000000
“DIPM”=dword:00000000

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\iaStor\Parameters\Port3]

“LPM”=dword:00000000
“LPMDSTATE”=dword:00000000
“DIPM”=dword:00000000

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\iaStor\Parameters\Port4]

“LPM”=dword:00000000
“LPMDSTATE”=dword:00000000
“DIPM”=dword:00000000

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\iaStor\Parameters\Port5]

“LPM”=dword:00000000
“LPMDSTATE”=dword:00000000
“DIPM”=dword:00000000

 

After you’re done, the Intel SSD Toolbox will show a warning in the system tuner (screenshot below), this is normal. You have intentionally disabled LPM/DIPM, do not click “Tune!”.

 

 

Windows 7 Desktop Icons and Shortcuts Disappearing

So your desktop shortcuts are missing?

If they are all missing, chances are they might have been deleted or somehow, either you or a program, has disabled desktop icons. See Method 1 below.

If some of your icons look funny, are missing thumbnails, or the desktop doesn’t “refresh” when you’ve placed new items on it, try Method 2 as your icon cache may be corrupted.

If your desktop icons are missing and they are all network, broken local shortcuts, or shortcuts to files on a removable USB drive, system maintenance is to blame. There are two methods to help with that:

  • Method 3 is the easy way. The downside is that it disables all system maintenance. I would only recommend this as a way to test if that is indeed the correct solution to your problem.
  • Method 4 is the recommended method, as it is less of a band-aid solution. It involves increasing the threshold that Windows will have before it starts cleaning up broken shortcuts.

 

Method 1: All Icons missing from Desktop

  1. Right-Click on an empty part of the Desktop.
  2. Hover over “View” and make sure “Show Desktop Icons” is checked.

 

Method 2: Rebuild The Icon Cache

Open notepad, paste the following code, and then save it as IconFix.bat. Go to where you saved the file and double click it. As an alternative, you can type the lines one-by-one in the command prompt (Start -> Search -> cmd -> Right-click and select “Run as Administrator”).

taskkill /F /IM explorer.exe
cd /d %userprofile%\AppData\Local
attrib –h IconCache.db
del IconCache.db
start explorer.exe

 

Method 3: Disable System Maintenance

  1. Go to the Start Menu -> Control Panel -> System and Security -> Under “Action Center” click on “Troubleshoot Common Computer Problems” -> Click “Change Settings” on the left side.
  2. Under “Computer Maintenance” select “off” and under “Other Settings” remove both checkmarks as shown in the screenshots below.

 

Method 4: Modify The Scheduled Task Files

Try this when your network shortcuts or broken shortcuts disappear from your desktop. Windows 7 has a broken-shortcut threshold of 4. Some people recommend deleting the script file, but modifying it to increase the threshold to a higher number is a safer way to do it, while still allowing system maintenance to run (unlike Method 3). This method does require a bit more work, and there is a greater risk to system damage than the previous methods. There are some screenshots below to help you along with the steps.

  1. Double-click on “Computer” on the Desktop, or right-click on the Start Menu and click “Open Windows Explorer.”
  2. Go to: C:\Windows\diagnostics\scheduled\Maintenance.
  3. Right-click on TS_BrokenShortcuts.ps1 and select “Properties.”
  4. Click on the “Security” tab.
  5. Click on “Advanced” near the bottom.
  6. The Advanced Security settings dialog will pop up. Click on the “Owner” tab.
  7. The Current Owner will show TrustedInstaller. Click “Edit” near the bottom.
  8. Under “Change Owner To:” select your username.
  9. Click “OK” to close the dialog. Click “OK” to the warning.
  10. After returning to the Advanced Security settings dialog, it will show your user as the current owner. Click “OK.”
  11. Now that you are back in the Security tab, click “Edit.”
  12. The Permissions dialog will pop up. You are now free to select a group or user and modify the permissions on the file. You will likely be part of the “Users” group. Select “Users” and under permissions select “Modify.”
  13. Click “OK” to return to the Security tab. Click “OK” again to exit the file’s properties.
  14. Right-Click on TS_BrokenShortcuts.ps1 and select “Edit.”
  15. On line 44, find “-gt 4))” -> Change this to “-gt 25))” to set the threshold to 25 broken icons. If you feel there may be more than 25 broken network icons on your desktop at a time, adjust accordingly.
  16. If you wish to use the same method for preventing the removal of unused icons, edit the TS_UnusedDesktopIcons.ps1 file following the steps above, find “-gt 10” on line 50 and change it to a higher number.

Reduce Windows 7 WinSxS Folder Size

With Windows Vista, the WinSxS folder was able to be cleaned up via a third party tool (WinSxS Lite here – Vista only!). With the initial release of Windows 7, we lost that capability – but it has since returned with Service Pack 1.

The WinSxS folder is used to store install and uninstall files, windows packages (current and previous versions of a component) and out-of-band releases. You should not completely delete this folder. Post Windows 7 SP1, there is now a way to remove the unnecessary files from this folder using the command line (elevated/admin mode -> Click Start -> Type “cmd” in Search. Right click on “cmd” and choose “Run as Administrator”). This is great for reducing the Windows folder size for SSDs and netbooks. In my case it saved 3.5GB of space.

 

dism /online /cleanup-image /spsuperseded

 

 

Before:

 

After:

How to Install PHP 5.3 FastCGI on Windows 2008 IIS 7

PHP on Windows has come along way in the past few years. It used to be a chore to get PHP to work properly on IIS. Not so, anymore.

In the past I’ve recommended PHP ISAPI for IIS when using threaded applications and accelerators like eAccelerator, xCache and APC. APC now includes support for FastCGI (Non-Thread Safe). To install PHP 4 – 5.2.x ISAPI, see my previous post: How to install PHP ISAPI on Windows 2008 IIS7 x64.

With PHP 5.3.x, the ISAPI dll has been removed for Windows. In order to use it, you’ll need to compile it yourself. There is a big push to use FastCGI on IIS, and with good reason – the performance has increased dramatically. Since most web applications (blogs, forums, CMS) do not require a Thread Safe install of PHP, FastCGI is the fastest and most stable option around.

PHP 5.3 for Windows is now compiled with either VC6 or VC9. VC9 should be used with IIS and VC6 should be used with Apache 1 or 2. For the VC9 versions you will need the Microsoft 2008 C++ Runtime (VC x86, VC x64, even though you are installing 32-bit PHP, install the correct version of VC++ for the version of Windows that you have).

When installing multiple versions of PHP with PHP Manager, each install can have a different PHP.ini and set of extensions installed and enabled. Within IIS, you can have a different version of PHP enabled for each site.

1. Download and Install PHP Manager for IIS 7/7.5. (http://phpmanager.codeplex.com/releases/view/59970) Even though PHP is 32-bit, install the version of PHP Manager that matches your install of Windows (x86 or x64).

2. Download and Install PHP 5.3.x for Windows VC9 (Non-Thread Safe). (http://windows.php.net/download/) You can use the installer or zip package. I’d recommend using the installer package if this is your first install, as it will set the PATH for your PHP install in Windows. If you are adding a second version or upgrading PHP, download the zip package and simply unzip it. If you plan to use multiple versions of PHP at the same time, I’d recommend naming your directories with the PHP version, ie: C:\php_5.3.5\.

3. In PHP Manager (IIS Manager -> Server Name -> PHP Manager), click on “Register New PHP Version” and browse to where you unzipped the PHP files. Select the php-cgi.exe file and click OK. Once you have registered the PHP module, you’ll need to configure the PHP.ini. This can be done in Notepad or within PHP Manager (Manage All Settings). For most basic installs, the default PHP.ini will suffice. If you are using a MySQL database, you’ll have to enable the MySQL or MySQLi extension. Go to IIS Manager -> PHP Manager -> PHP Extensions -> Enable or disable an extension. Click on php_mysql.dll and/or php_mysqli.dll and under Actions on the right side bar, click Enable.

4. If you are using Windows x64, you’ll need to set your application pool settings to allow 32-bit PHP to function. If you are using 32-bit Windows, skip this step. In IIS Manager -> Application Pools -> Right-Click on the website’s application pool (or Default if you haven’t set one up yet) and select Advanced Settings. Set “Enable 32-bit applications” to TRUE. Click OK. This spawns the App Pool in 32-bit mode, so if you have other modules that need to be run in 64-bit mode, best to separate the website into two App Pools: one 32-bit and one 64-bit.

5. If you want to install multiple versions of PHP, all you need to do is register each version using PHP Manager. You can click on each individual website and select a specific version of PHP to run. Remember to modify the PHP.ini of each version you register. If you get CGI errors when trying to view a webpage, make sure cgi.force_redirect = 0, or it is commented out in the PHP.ini.