Hơ, có vẻ như bạn ngoc_viet08 chưa hiểu được bản chất vấn đề chứ ý tưởng này hữu ích cho những site có dữ liệu lớn đấy chứ?
Hãy lấy 1 ví dụ đơn giản, site A có 2 bảng:
- Bảng config: name, value - chỉ có vài record về cấu hình cơ bản của site.
- Bảng content: id, intro, body - với số records lên đến hàng chục, trăm nghìn, thậm trí là hàng triệu.
Mình bắt đầu so sánh:
1. Cách truyền thống:
PHP Code:
<html>
<head>
<title><?php print $config->site_title; ?></title>
</head>
<body>
<?php
// Proccess this content
$query = mysql_query("SELECT * FROM content WHERE id = ". $_GET***91;'id'***93;);
while ( $row = mysql_fetch_object($query) ) {
// Print content here
}
?>
</body>
</html>
2. Ý tưởng của chủ thớt:
PHP Code:
<html>
<head>
<title><?php print $config->site_title; ?></title>
</head>
<body>
<?php
// Proccess this content
if ( file_exists("content-$i.php") ) {
// Just included the file, not need any query.
include("content-$i.php");
} else {
// Server is overloaded :-P.
$query = mysql_query("SELECT * FROM content WHERE id = ". $_GET***91;'id'***93;);
while ( $row = mysql_fetch_object($query) ) {
// Print content here
}
}
?>
</body>
</html>
Mời các bác comment về optimization!
Bookmarks