2013-05-02 2 views
0

내 문제는 내 페이지로드가 매우 느립니다 .... (2-3 초) 문제의 원인이 어디에서 테스트되었으며 그 부분은 $ query = mysql_query ....입니다. .. 여기 느린 mysql 데이터로드

은 페이지입니다 :

require_once('config/db_config.php'); 
require_once 'class/PHPTemplate.class.php'; 
session_start(); 
//Connect to mysql server 
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); 
if(!$link) { 
    die('Failed to connect to server: ' . mysql_error()); 
} 
//Select database 
$db = mysql_select_db(DB_DATABASE); 
if(!$db) { 
    die("Unable to select database"); 
} 
$query = mysql_query("SELECT * FROM pages WHERE url_address='Skarabeol'"); 
$numrows = mysql_num_rows($query); 
if($numrows!=0) { 
    while ($row = mysql_fetch_assoc($query)) { 
     $content=$row['content']; 
     $title=$row['title']; 
    } 
} else {Echo "Page not found!";} 
$rows = array(
    array(1.1, 1.2, 1.3), 
    array(2.1, 2.2, 2.3), 
    array(3.1, 3.2, 3.3), 
    array(4.1, 4.2, 4.3) 
); 
$tpl = new PHPTemplate(); 
$tpl->add('title', $title); 
$tpl->add('content', $content); 
$tpl->add('current_year', date('Y')); 
//$tpl->add('rows', $rows); 
//$tpl->add('rows_count', count($rows)); 
$tpl->load('footer', 'tpl/footer.tpl'); 
$tpl->display('tpl/page.tpl'); 
?> 

그리고 (내가 mysql을 연결하지 않고 테스트하고 괜찮 았는데) 템플릿 파일을로드합니다. 여기

내가 뭘 잘못

define('DB_HOST', 'localhost'); 
    define('DB_USER', 'xxxxxxx'); 
    define('DB_PASSWORD', 'xxxxxxxxxx'); 
    define('DB_DATABASE', 'xxxxxxxxx'); 

... 경우에 당신이 그것을보고 싶어에서 설정 파일입니까?

나에게 다른 것을 보여줄 필요가 있다면 알려 주시기 바랍니다 .... 미리 감사드립니다!

+2

당신이'url_address'에 인덱스를 가지고있다? – AlexP

+1

또한'SELECT *'는 모든 열 이름을 나열하는 것보다 느립니다. – AlexP

+0

페이지 테이블에 얼마나 많은 데이터가 있습니까? 이 데이터베이스 서버는 어디에 위치합니까? – MatthewMcGovern

답변

0

SQL 통계를 보려면 프로파일 링을 사용해보십시오.

mysql> set profiling=1; 
Query OK, 0 rows affected (0.00 sec) 

mysql> select sql_no_cache * from tblwebentry where webID = 433382; 
+--------+-----------------------------+-----------------------------------------------------+------------+--------------------+---------------+-------------+---------+-------------+---------------+----------------+---------+ 
| webID | webEntryName    | webAddress           | webMessage | webStdCodeSearchID | webPriorityID | webRadiusID | webLogo | webLatitude | webLongtitude | webShowAddress | websort | 
+--------+-----------------------------+-----------------------------------------------------+------------+--------------------+---------------+-------------+---------+-------------+---------------+----------------+---------+ 
| 433382 | Allen House Business Centre | Allen House, The Maltings, Sawbridgeworth, CM21 9JX |   |    100 |    1 |   1 |   | 51.812466 |  0.159480 | 1    |  1 | 
+--------+-----------------------------+-----------------------------------------------------+------------+--------------------+---------------+-------------+---------+-------------+---------------+----------------+---------+ 
1 row in set (0.00 sec) 

mysql> show profile; 
+--------------------+----------+ 
| Status    | Duration | 
+--------------------+----------+ 
| starting   | 0.000029 | 
| Opening tables  | 0.000010 | 
| System lock  | 0.000002 | 
| Table lock   | 0.000005 | 
| init    | 0.000018 | 
| optimizing   | 0.000006 | 
| statistics   | 0.000030 | 
| preparing   | 0.000007 | 
| executing   | 0.000002 | 
| Sending data  | 0.000041 | 
| end    | 0.000003 | 
| end    | 0.000002 | 
| query end   | 0.000002 | 
| freeing items  | 0.000005 | 
| closing tables  | 0.000003 | 
| logging slow query | 0.000001 | 
| cleaning up  | 0.000003 | 
+--------------------+----------+ 
17 rows in set (0.00 sec) 

또한 시도 :

mysql> EXPLAIN SELECT wciid, wcIname FROM tblwebclassification WHERE wciname = 'plumbers'; 
+----+-------------+----------------------+------+---------------+------+---------+------+------+-------------+ 
| id | select_type | table    | type | possible_keys | key | key_len | ref | rows | Extra  | 
+----+-------------+----------------------+------+---------------+------+---------+------+------+-------------+ 
| 1 | SIMPLE  | tblwebclassification | ALL | wcIName  | NULL | NULL | NULL | 1702 | Using where | 
+----+-------------+----------------------+------+---------------+------+---------+------+------+-------------+ 
1 row in set (0.00 sec)