0

I found other posts about this, but I could not solve my problem.

When I run a query by PHPMyAdmin, the query runs in 9 milliseconds

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

However, when you run the same query in the PHP server, the query takes 0.14 seconds.

$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>";

How can I solve this problem? I need to reduce my site load time.

The same goes for the connection to the database. This taking 0.41 seconds. I think this time needs to be lowered

Testpage http://omenorpreco.com/teste.php

UPDATE:

  • my mysql server is Windows (WAMP)
  • already includes the variable skip-name-resolve the configurations file
  • the connection is made by ip, not the server name
  • 9
    • Check how PMA runs a query and measures time. Without knowing how exactly and what exactly it measures - you compare apples to bananas. Commented Jul 19, 2016 at 0:27
    • Zerkms, what you mean? The same query is executed in PMA and php(page) Commented Jul 19, 2016 at 0:30
    • 1
      Right. "and say query execution time is" --- and you know what exactly and how exactly they did measure? Don't trust the number, check their code and find how they got it. Commented Jul 19, 2016 at 0:37
    • 1
      I am not stating it is incorrect. I'm stating that you don't know what that number means. When you make performance optimisations - trust no one but yourself. If you are not capable of checking how PMA is doing that - then the whole optimisation procedure is not that important for you. Commented Jul 19, 2016 at 0:42
    • 2
      You are still comparing apples to bananas. Commented Jul 19, 2016 at 1:16

    1 Answer 1

    1

    According to https://stackoverflow.com/a/15293336/4275413 phpMyAdmin displays the query time that is reported from mysql itself, your script has all the overhead with wrappers, the mysqli library and stuff.

    Sign up to request clarification or add additional context in comments.

    Comments

    Your Answer

    By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.