I'm trying to improve the performance of my pages to improve the user experience, but I'm not able to identify the problem.
According to Google, it is recommended that pages respond in less than 0.4 seconds, but only the connection to the database is taking 0.41 seconds. Being mysql_connect or mysqli_connect
In addition, the same query that I run to build a menu in PHP takes an average of 0.14 but in phpMyAdmin it takes only 0.0009 as shown in the execution
Showing records from 0 - 24 (35 total, Query took 0.0009 sec)
I created an empty page, only with the connection and the query to measure the times
http://omenorpreco.com/teste.php
How can I shorten the time to connect , and shorten the query time to get the same as 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>";