Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP, MySQL, IIS7.5 is taking far too long for simple queries

I've created a simple PHP test page which connects to a MySQL database, selects one int value, and then frees the result. The page takes 5 seconds or more to load. I've seen a lot of posts about this or similar issues but not of the resolutions have worked. Here is the output I'm getting:

mysql_connect took 4.8948628902435 seconds
mysql_select_db 0.00073790550231934 seconds
mysql_query took 0.0013959407806396 seconds
mysql_free_result took 2.0980834960938E-5 seconds

As you can see, the connection takes far too long and everything else is fast.

What I've tried

  • Disabled IPv6
  • Used IP instead of FQDN for the MySQL host.
  • Tweaked some config settings.

The Facts

  • All other non-PHP sites respond instantly.
  • Pinging the MySQL server give 1ms latency.
  • Querying the database using MySQL Query Browser gives instant response times.

FYI - I don't do PHP so it's okay to treat me like a baby when suggesting fixes.

The Test Script

<?php
    $mtime = microtime();
    $mtime = explode(' ', $mtime);
    $mtime = $mtime[1] + $mtime[0];
    $starttime = $mtime;

    mysql_connect("the_ip||the_hostname", "the_username", "the_password");

    $mtime = microtime();
    $mtime = explode(" ", $mtime);
    $mtime = $mtime[1] + $mtime[0];
    $endtime = $mtime;
    $totaltime = ($endtime - $starttime);
    echo '<h2> mysql_connect took ' .$totaltime. ' seconds</h2>';
?>

Trace route is instantaneous: By the way, the application in question is MantisBT as well as Wordpress.

  1     2 ms    <1 ms    <1 ms  1.2.3.4
  2    <1 ms    <1 ms    <1 ms  MYSQL5 [5.6.7.8]
like image 587
Josh M. Avatar asked Dec 17 '22 16:12

Josh M.


2 Answers

Another thing to look at is "mysql_connect" which might show you that PHP is having a hard time resolving (finding) the mysql host. Are you using a IP address, localhost, or hostname? (when connecting to the database in php) If it's a hostname try and add the IP to c:\windows\system32\drivers\etc\host

if that doesn't work. If all your "The Facts" are correct then you might have a issue with your php script. Can you post it so I can see what you are running? Also post the mysql table info like "Indexes" etc.

:)

like image 163
RichardW11 Avatar answered Dec 19 '22 05:12

RichardW11


I had a similar problem, PHP was accessing MySQL with a simple select statement but taking for ages to display.

With help from another forum, the guy suggested that I make a new website and give it a different port than 80, so I did, In IIS manager, under sites, add new site and point it to the virtual DIR, entered the IP address of the server 192.168.2.2 and gave it port 82.

Opened port 82 in firewall and from a networked XP machine entered into the browser 192.168.2.2:82 and it was lightening. Worked first time.

Also, in the IIS manager for the new website, In Output Cacheing, Uncheck Use-mode cache, and it lets the pages run and enter data using the php pages.

A bit late with the reply, but thought I would share it any ways.

like image 21
Paul Grimes Avatar answered Dec 19 '22 05:12

Paul Grimes