Time difference in execution of the same query between PHP and PHPMYADMIN

Asked

Viewed 520 times

0

I am trying to improve the performance of my pages to improve the user experience, but, I am not able to identify the problem.

According to Google, it is recommended that the pages respond in less than 0.4 seconds, however, only the connection to the database, this taking 0.41 seconds. Whether by mysql_connect or mysqli_connect

Also, the same query I run to mount a menu, in PHP it takes on average 0.14 but in phpMyAdmin it only takes 0.0009 as shown in execution

Showing records from 0 - 24 (total 35, Query took 0.0009 sec)

I created an empty page, only with connection and query to measure times

http://omenorpreco.com/teste.php

Anyone have any idea how can I decrease the time to make the connection, and, decrease the query time to turn into Phpmyadmin?

UPDATE:

//PHP
    $sql = "select cd_categoria, linha, slug, cd_categoria_site, qtd from ( SELECT cd_categoria, if (menu.cd_categoria_pai=0,menu.nm_categoria,concat((select nm_categoria from tb_st_category where cd_categoria = menu.cd_categoria_pai),';',nm_categoria)) as linha , if (menu.cd_categoria_pai=0,menu.nm_slug,concat((select nm_slug from tb_st_category where cd_categoria = menu.cd_categoria_pai),'/',menu.nm_slug)) as slug , cd_categoria as cd_categoria_site , 0 as qtd FROM tb_st_category menu where cd_categoria_pai = 0 ) as a order by linha";
    $pagespeed = microtime_float();
    $query = $mysqli->query($sql);
    echo "Query Time:".number_format(microtime_float()-$pagespeed, 2, ',', '')."<br>";

  • My SQL server is Windows (WAMP)
  • Ja includes the Skip-name-resolve variable in the WAMP configuration file
  • Connection is remote, done via IP, not the server name
    • 1

      Is this query or is this different from php? Show how you did your test php code. However I think you’re confusing.

    • I updated the post with the PHP data (I just did not put the code of the connection with the database, but it is mysqli (I have tried with mysql as well)

    1 answer

    3

    This performance test is PHP and not query, so it will give different results always, to debug a query you can use the set profiling=1;

    mysql> set profiling=1;
    mysql> EXPLAIN SELECT ...
    mysql> SELECT ...
    mysql> ALTER ...
    mysql> show profiles;
    +----------+------------+-------------------------
    | Query_ID | Duration   | Query
    +----------+------------+-------------------------
    |        1 | 0.00036500 | EXPLAIN SELECT sbvi.id a
    |        2 | 0.00432700 | SELECT sbvi.id as sbvi_i
    |        3 | 2.83206100 | alter table sbvi drop in
    |        4 | 0.00047500 | explain SELECT sbvi.id a
    |        5 | 0.00367100 | SELECT sbvi.id as sbvi_i
    +----------+------------+-------------------------
    

    Documentation: http://dev.mysql.com/doc/refman/5.7/en/show-profile.html

    • Ola Guilherme, I used the command you gave me and apparently, the result is lower 1 - 0.00067650 - select cd_category, line, Slug, cd_categoria_sit...

    • I wanted to understand why PHP is more time consuming anyway? Why has network traffic? And by Phpmyadmin is directly on the same machine the PHP server and the database?

    • @Rodrigomendes phpmyadmin is a tool written in php, however their results of time should be with the profile and have nothing to do with PHP, as in the example, the test you created is using PHP functions, ie one test has nothing to do with the other, has no reason to compare both.

    • OK William, now I understand what you were trying to say. But is there a way for me to decrease this time in php? Because through Google speed test, my page is taking 2 or 3 seconds to load, but the querys are already super optimized. As a test, I put some runtime variables of each query in the http://omenorpreco.com/product/oculos-oakley-conquest-polarized-tan footer. The recommended by google is that the server respond in less than 200ms. .

    • I believe that the best solution is to use cache and CDN, as well as to use more robust servers with higher bandwidth. I believe the problem may be in the configuration of NGINX or of Apache (do not know which uses). Of course, use also an updated version of PHP, usually recent versions are faster than previous. : P

    • I use the godaddy server, can I handle these settings this way? Cache I already use, but CDN? Is it a paid service? Sorry I don’t know.

    Show 1 more comment

    Browser other questions tagged

    You are not signed in. Login or sign up in order to post.