PHP very slow on IIS7 RRS feed

  • Question

  • User-1753269205 posted

    New install of Win2008 and IIS7... setup php using following instructions http://learn.iis.net/page.aspx/246/using-fastcgi-to-host-php-applications-on-iis-70/

    php pages are slow, especially the ones that connect to the mysql database. One page in particular will take so long that I get a 500 error (assuming this is timeout problem).

    I am only calling up 10 records with 2 fields to display.

    PHP error log shows nothing. IIS log shows nothing relating to this problem.

    I have copied the exact code to our IIS6 server and the pages come up fast. I coped the pages to the Apache/Windows server and the pages come up fast.

    This tells me something wrong on the IIS7 server.

    How to resolve??

    Thank you!








    Sunday, November 30, 2008 4:20 PM

All replies

  • User2093557029 posted

     Have you compared the php.ini from your IIS 6 server to your IIS 7 server? I can't think of anything off the top of my head that would cause PHP to be slow on IIS other than networking related issues such as TCP/IP connectivity/name resolution, etc. Is it just PHP that is slow, or is other content served by IIS slow as well?

    Sunday, November 30, 2008 6:27 PM
  • User-1753269205 posted

    IIS6 is using ISAPI.

    HTML pages come up fine. the php page is fine as long as their is no mysql connection from what I can tell.

    Slow down with PHP pages connecting to MySQL locally are slow too. This one particular page will take 5 - 10 seconds to display and at times a 500 error will occur or content is blank.

    Monday, December 1, 2008 12:32 AM
  • User2093557029 posted

    What happens if you run the SQL locally via the MySQL command line client? Does it still take a long time? Might be an idea to enable the MySQL slow query log if you haven't already.

    Monday, December 1, 2008 4:42 AM
  • User-2026410440 posted
    What version of PHP are you using? I've heard anecdotally that some people have database connectivity issues with 5.2.6...you might try going back to 5.2.5 to see if it gets any better. bill
    Friday, December 5, 2008 6:28 PM
  • User-1753269205 posted

     Thanks to everyone for help. Figured out the problem was a tcp/ip problem between iis7 server and mysql server!

    Friday, December 5, 2008 6:54 PM
  • User-2005194410 posted

    Can you tell us more about the problem and how you have resolved it?


    Sunday, December 7, 2008 3:30 AM
  • User1066072018 posted

    Anyone have more insight in how to troubleshoot and remedy this? PH 4 currently outperfoms PHP 5 10 fold using FCCGI for us, in fact PHP 5 is so slow using MySQL as to be unusable.

    Monday, June 1, 2009 7:46 AM
  • User2093557029 posted
    Do you have the same performance issue with PHP 5 using ISAPI? Any warnings/errors in your PHP log? Are any network connections been made by PHP?
    Tuesday, June 2, 2009 7:09 PM
  • User1066072018 posted

    I haven’t tried ISAPI as I am using NTS version of PHP5(problem still occurs on TS version, but I will try TS ISAPI). Problem does not happen using FCGI on IIS 6. MySQL is on a dedicated server separate to the web server, so network connection are being made(latency <1ms and gigabit links). PHP 4 running FCGI works fine, PHP 5 slow as a dog(as in times out 8 out of 10 times) and really have run out of ideas, communication appears fine between the servers otherwise.

    <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>Platform is as such. Web edition web servers, with content stored on file server, accessed via UNC paths with AD authentication. Problem still occurs if data stored on local drives with local users however, and even if I install MySQL on the web server performance is no better. Only thing I can think of is that the web servers are virtualised on Xen and/or the MySQL server runs Linux, but am not sure how to dig deeper to see where the problem lies. Problem is with FCGI PHP 5 and MySQL only, other languages(classic asp, ASP.net, Perl) all working fine when using MySQL as the data store.<o:p></o:p>


    Tuesday, June 2, 2009 8:03 PM
  • User2093557029 posted

     You're right, that doesn't seem to make a whole lot of sense on face value. So you're saying that PHP 4 using FastCGI on the same servers, connecting to the same MySQL server and running the same PHP application is performing better? Is this custom code, or are you using a publically available PHP app? What sort of page loading times are we talking about (2 secs, 5 secs, etc)?

    Wednesday, June 3, 2009 1:20 AM
  • User1066072018 posted

    All PHP code that makes mysql connections (wordpress, Joomla, Drupal) etc.

    PHP 4 loading times - normal ~1 second. PHP 5 same application (Joomla just tested on) Timout after 30 seconds. Same server.

    Wednesday, June 3, 2009 4:07 AM
  • User2093557029 posted
    If it is timing out (rather than just running slow) I'd be looking at enabling and checking your php log. Rather than bothering with ISAPI I would give normal CGI a go as it's output can sometimes be a little more verbose than the other API's.
    Wednesday, June 3, 2009 9:07 AM
  • User-824108913 posted

    Hi Guys,

    We switched over to fastcgi on friday so we could move to the new sqlsrv driver for php. However, we no have the delay problem as described above.

    I tried the mysql solution to turn of the dns lookup, but this had not effect.

    The problem is not related to the sqlsrv driver, as we have not implemented it.

    Under isapi, the system runs correctly. But after switching to fastcgi and following the guide at http://learn.iis.net/page.aspx/246/using-fastcgi-to-host-php-applications-on-iis-70/, it now performs very slowly.

    Whilst observing the mysql perfromance, only towards the end of the 15 second response time, does the mysql kick in and the queries are seen coming through.

    What I don't understand is why under isapi it works fine, but under fastcgi it doesn't, ans furthermore, how could this be then related to mysql?

    Would greatly appreciate anyones input.


    Sunday, September 20, 2009 6:00 AM
  • User2093557029 posted

    Have you tried under standard CGI? Also, have you set up your PHP logging?

    Thursday, September 24, 2009 3:34 AM
  • User97111691 posted

    I can imagine two possible sources for this problem:

    • IPv6 is enabled and localhost does not exist or ::1
    • Mysql's libmysql is used instead of PHP's libmysql.

    It happens that the IPv6 problem was the cause for this problem (as you stated later). The 2nd possibility happens a lot when someone installs mysql after PHP, or do a mysql update after having installed PHP.

    The latest Mysql's libmysql is not compatible with php's libmysql (and many other, that's not a php specific problem). They suffer from ABI compatibilities issues. The solution is to alter your PATH to be sure that php is first defined( PATH=c:\PHP;c:\mysql for example).


    Thursday, September 24, 2009 5:57 AM
  • User-824108913 posted

    Hi Brash and Pierre,

    I meant to update this post!

    I solved the problem be starting with the php.ini-recommended file and building it up slowly to what I needed, removing some extensions in the process. Unfortunately I could not find what was causing the speed problem, which is a little frustrating.

    However, I think the solution i found illustrates a strategy that should ideally be taken when upgrading / changing php modes / version. Start first with the basic setup, and slowly updated the settings to be equal or at least the base requirements of ones own system.

    Just making the changes to the current php.ini file for the new setup is not really ideal.

    So, my lesson learnt!

    Thanks for the advice though.


    Thursday, September 24, 2009 8:36 AM
  • User498746093 posted


    As I have the same problem and your solution seems to be worth the try, can you tell me in what file I need to set the path?


    Sunday, November 29, 2009 3:26 PM
  • User-375698240 posted

    My problme was resolved by disabling IPv6

    Monday, January 4, 2010 2:43 PM
  • User-412902039 posted

    Hello Guys,

    I have read this post many times and tried all possible solutions. None of them worked for me. So I will share my solution with you guys. It as simple as can be sometimes...

    We had fastcgi setup on IIS7 and php installed on our d: drive in the dir d:\php5. Yes the NTS version. Pages we're really loading slow and f.e. a zencart shop would take about 4 seconds to load. Then finally after a lot of testing (and i mean a lot: different faster hardware, parse times, query times and so on) i found out that installing php with the web platform installer in the default directory C:\Program Files (x86)\PHP solved all our performance issues!

    Ronald Kunenborg

    Reda Internet.

    Thursday, March 18, 2010 9:03 AM
  • User-264051711 posted

    I thought PHP was slow on IIS7 for me also... but I think it is actually a MySQL thing for me.

    Tuesday, May 4, 2010 1:53 AM
  • User453036086 posted

    I had the same problem. Had me baffled for hours. But, it would appear that is an IPv6 issue or and issue with localhost to be precise. With IPv6 enabled, PHP struggl;es to resolve localhost to the loopback address of

    You can disable IPv6, but if you need to leave IPv6 enabled changing 'localhost' to '' in your scripts haas the same result. Maybe this will be addressed in the next version of PHP?


    Tuesday, May 11, 2010 1:47 PM
  • User1399393924 posted

     I had similar problem updating 5.2 to 5.3. The only solution was downgrade to 5.2. Must be a bug on 5.3.

    Monday, July 18, 2011 5:24 PM
  • User1848989227 posted

    I had the same problem. Had me baffled for hours. But, it would appear that is an IPv6 issue or and issue with localhost to be precise. With IPv6 enabled, PHP struggl;es to resolve localhost to the loopback address of

    You can disable IPv6, but if you need to leave IPv6 enabled changing 'localhost' to '' in your scripts haas the same result. Maybe this will be addressed in the next version of PHP?


    I know this is an old discussion, but I thought I'd just reply to say qwarrior's post instantly solved my slow loading issue.

    Having uninstalled PHP, reinstalled using Web Platform installer, changing PHP install from thread safe to non-thread safe and a multitude of other suggestions I found, simply changing the db connection settings in the PHP script from localhost to transformed the PHP site from very slow loading to virtually instantaneous.

    The eventual install was through Web Platform Installer with PHP 5.3.7 on IIS 7 with FastCGI update.

    Thanks for posting this! :)
    Thursday, August 18, 2011 2:31 PM
  • User-880406344 posted

    Same issue - now fixed.  Changed "localhost" for MySql Connections in my PHP code to "".  Instantly fixed.   Must be the IPv6 issue noted.

    Thanks to everyone for your posts!!

    Friday, January 13, 2012 2:11 PM
  • User-797159719 posted

    For me as well the solution recommended by qwarrior took care of the issue here. We have PHP 5.3.10, if that helps.


    Monday, February 27, 2012 4:36 PM
  • User-813868943 posted
    I am also having this issue although in my case it is random. sometimes pages will load fine and then randomly some pages will take ages to load. MySQL is not on the same server so it is not a localhost/ipv6 issue. I am using the Web Platform Installer default PHP 5.3.x install with fastcgi. I have also installed the latest wincache update to fix known php issues.
    Wednesday, February 29, 2012 7:29 AM
  • User-201428385 posted
    we has iis7, php5.3.10, mysql running on one box. Our problem is that first byte response slow, even i used as the connection host, it doesn't work. Someone talked about ipv6 issue. we set the Type 0xffffffff to disable all IPv6 components in regedit. how to disable ipv6 link http://support.microsoft.com/kb/929852 anyone knows how to solve the problem?
    Tuesday, April 10, 2012 4:05 AM
  • User498746093 posted
    We've had that problem long time ago. We found out that ( for us) it had to do with the order we've installed PHP and MySql. But I can't remember which one had to be first... I know we've de-installed both and re-installed it after. Logically I would think it has to be PHP. Maybe this works for you too. Good luck!
    Tuesday, April 10, 2012 4:15 AM
  • User-813868943 posted
    I am having more of a random issue. every so often pages on any php sites will go slow and might take a minute or more to load, then if I reload the page it will be fine. MySQL is not on the same server, so it is not a localhost issue.
    Wednesday, June 27, 2012 8:59 AM
  • User621231110 posted

    Hi lordg,

    I have a Windows Server 2008R2 Environment with IIS7 and PHP 5.3.
    When working with php based CMS's, mainly Wordpress, it was awfully slooooow!

    I thought it has something to do with slow MySQL connection issues (for the machine is also running SQL Server), so I purposely set up a Linux Server from an old PC, just to install MySQL. 

    Same issue, so it was clear it had nothing to do with MySQL..

    Then I checked php.ini line by line, and I found that my problem was related with this particular setting:

    output_buffering = 4096

    I changed it to output_buffering = Off

    Now it's running like a breeze Cool

    Thanks for suggesting to check php.ini!! Wink

    Thursday, February 6, 2014 2:29 PM
  • User1873786028 posted

    Using instead of localhost for connecting to MySQL worked for me as well (MySQL 5.5,PHP 5.3.28, IIS 8).  My web page loads went from 3-6 seconds to less than 2.

    Friday, April 15, 2016 10:28 PM