หัวข้อ: วิธีใส่แคชแบบนี้ถูกต้องมั้ยครับ (เขียนไม่เป็นอะครับ งงมากมาย) เริ่มหัวข้อโดย: technomatch ที่ 05 สิงหาคม 2009, 13:39:20 ออกตัวก่อนนะครับคือผมไม่ได้เรียนเขียนเว็บหรือมีความรู้เรื่องphp มาเลย(ได้วุฒิแค่มอหกอะครับ) :P
ปัญหาคือเอาไปใช้แล้ว ตัวแคชมันสร้างไฟล์ .html ขึ้นมาในได/cache/... เว็บหน้าแรกที่เข้าไปโหลดเร็วขึ้น..แต่รู้สึกว่าผมทำอะไรผิดไป เพราะเข้าไปแต่ละหน้า...มันจะแสดงหน้าที่ผมโหลดไปเมื่อตะกี้นี้... ผมสงสัยไอ้เจ้าตัว .$reqfilename. มันต้องใส่เป็นอะไรหรือทำแบบไหนถึงจะให้มันสร้างแคชทุกๆหน้าครับ ตัวในแคชผมเข้าใจว่ามันน่าจะเป็น ชื่อเพจ.html มากกว่า อันนี้รายละเอียดไฟล์ .htaccess ของผม....ไม่รู้ว่าต้องแปลงอะไรรึเปล่า RewriteEngine On RewriteRule ^(.*)/([0-9]*).html index.php?pro=$1&page=$2 [L] RewriteRule ^(.*)/(.*).html hotel.php?p=$1&n=$2 [L] RewriteRule ^(.*).html index.php?pro=$1 [L] อันนี้สคิปแคชที่ผมใช้อยู่ที่ index.php <?php $cachefile = "cache/".$reqfilename.".html"; $cachetime = 5 * 60; // 5 minutes // Serve from the cache if it is younger than $cachetime if (file_exists($cachefile) && (time() - $cachetime < filemtime($cachefile))) { include($cachefile); echo "<!-- Cached ".date('jS F Y H:i', filemtime($cachefile))." -->n"; exit; } ob_start(); // start the output buffer ?> .. Your usual PHP script and HTML here ... <?php // open the cache file for writing $fp = fopen($cachefile, 'w'); // save the contents of output buffer to the file fwrite($fp, ob_get_contents()); // close the file fclose($fp); // Send the output to the browser ob_end_flush(); ?> ยังไงใครรู้ก็รบกวนนิสนึงนะครับ :-* แก้ไข...ผิดไฟล์ 5555 :-* |