PHP, MySQL, IIS7.5 are too long for simple queries

I created a simple PHP test page that connects to a MySQL database, selects a single int value and then frees the result. It takes 5 seconds or more to download. I have seen many posts about this or similar issues, but not about resolutions. Here is the result I get:

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 too much time, and everything else is fast.

What i tried

  • Disabled IPv6
  • Used IP instead of FQDN for MySQL host.
  • Change the configuration settings.

Data

  • All other non-PHP sites react instantly.
  • MySQL pinging server gives 1 ms latency.
  • Querying a database using MySQL Query Browser gives instant response time.

FYI - I do not do PHP, so it’s good to treat me like a child, offering corrections.

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>'; ?> 

Route tracing is instant: By the way, this is the MantisBT application, 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] 
+4
source share
3 answers

Another thing worth paying attention to is "mysql_connect", which can show you that PHP has difficulty deciding (finding) a mysql node. Are you using IP address, localhost or hostname? (when connecting to the database in php) If this is the host name, try and add the IP to the c: \ windows \ system32 \ drivers \ etc \ host directory

if it does not work. If all your Facts are correct, you may have a problem with your php script. Can you post it so I can see what you are using? Also post mysql table info like "Indexes" etc.

:)

+7
source

I had a similar problem, PHP accessed MySQL with a simple select statement, but displayed over the centuries.

Using another forum, the guy suggested I create a new website and provide him with a different port than 80, so I did it in the IIS manager under the sites, added a new site and pointed it to the virtual DIR, the IP address of the server 192.168.2.2 was entered and gave him port 82.

He opened port 82 in the firewall and from the XP network computer, entered into the browser 192.168.2.2:82, and he became silent. He worked for the first time.

In addition, in the IIS Manager for the new website, “In Output Cache,” clear the “Use Mode” check box, and it allows you to launch pages and enter data using php pages.

A little late with the answer, but thought that I would share with him by any means.

+3
source

Can you try these two test scripts? (Note the change to microtime - the thing you do is an ancient hack of PHP4 ... you are not using PHP4, are you?)

This will check the MySQLi extension, if available:

 <h1>MySQLi Test</h1> <?php $starttime = microtime(true); $db = new mysqli("the_ip||the_hostname", "the_username", "the_password"); $endtime = microtime(true); $totaltime = ($endtime - $starttime); echo '<h2> mysqli_connect took ' .$totaltime. ' seconds</h2>'; 

And this checks the PDO extension, if available:

 <h1>PDO Test</h1> <?php $starttime = microtime(true); $db = new PDO("mysql:host=host_or_ip", "the_username", "the_password"); $endtime = microtime(true); $totaltime = ($endtime - $starttime); echo '<h2>PDO took ' .$totaltime. ' seconds</h2>'; 

If both of them experience the same delay, then we know this not only in the ancient mysql code extension.

+2
source

Source: https://habr.com/ru/post/1345030/


All Articles