1. Halo Guest, pastikan Anda selalu menaati peraturan forum sebelum mengirimkan post atau thread baru.

[HELP] Cara bikin sistem cache utk web php

Discussion in 'Pemrograman Web' started by gokslob, Nov 26, 2011.

  1. gokslob

    gokslob Ads.id Fan

    Joined:
    Mar 27, 2010
    Messages:
    102
    Likes Received:
    0
    Ane mo minta tolong ama pakar2 programming yg ada di ads-id,,

    Kemaren web ane (berbasis php) kena suspend ama host karna katanya
    loading trafiknya terlalu tinggi,, host minta supaya halaman web ane
    ditambahin sistem cache untuk ringanin beban server.

    Kalo di wp kan ada tuh ya plugin semacam super cache,, nah kalo untuk
    web php gimana nambahinnya yak?? ane buta amat soal programming :(

    Tolong ya mastah2 programmer bisa bantuin ane,,

    Sempat search di gugel ane nemu di _http://www.jroller.com/RickHigh/entry/created_new_caching_mechanism_to
    ada kode cache tapi gak ngerti juga itu bisa dipake apa nggak, dan gimana
    cara makenya (kodenya kepanjangan, gak bisa ane kopas di sini).

    Dooh,, pusing deh ane. please help.........
     
  2. masadi

    masadi Super Hero

    Joined:
    Dec 12, 2010
    Messages:
    2,334
    Likes Received:
    144
    Location:
    mas-adi.com
    coba disini mas bro...
    _http://theukwebdesigncompany.com/articles/php-caching.php
    Keknya cocok deh... :D
     
    gokslob likes this.
  3. gokslob

    gokslob Ads.id Fan

    Joined:
    Mar 27, 2010
    Messages:
    102
    Likes Received:
    0
    makasi banget infonya mas bro,, :D

    tapi masih lom paham kode
    PHP:
    <?php
          $cachefile 
    "cache/".$reqfilename.".html";
           
    $cachetime 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($fpob_get_contents());
            
    // close the file          fclose($fp); 
            // Send the output to the browser         ob_end_flush(); 
    ?>
    langsung ditaro di antara kode lain di file index.php gitu ya gan?

    berarti semua script index.php ane lainnya mulai dari awal=>
    PHP:
    <?php
    include("setting/config.php");include("fungsi/fungsi.php");
    config();
    cek();
    tambahwaktu(d,$bataswaktu);
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    sampe bagian ahir=>
    PHP:
    ?>
    </BODY>
    </HTML>
    <?
    koneksi();
    $SQL="UPDATE  member SET traffic= traffic+1 WHERE id ='$id_sesi'";
    mysql_query($SQL);
    ?>
    ditaroh di tengah2 kode itu ya gan? (gantiin tulisan: '.. Your usual PHP script and HTML here ...')?

    trus gan, itu murni penambahan kode aja tanpa ada perlu bikin file baru segala ya?
     
  4. GentZu AoZora

    GentZu AoZora Forbidden

    Joined:
    Nov 28, 2010
    Messages:
    2,932
    Likes Received:
    275
    Location:
    Bandung City
    mana sitenya?
     
  5. gokslob

    gokslob Ads.id Fan

    Joined:
    Mar 27, 2010
    Messages:
    102
    Likes Received:
    0
    _
     
    Last edited: Jun 8, 2013
  6. GentZu AoZora

    GentZu AoZora Forbidden

    Joined:
    Nov 28, 2010
    Messages:
    2,932
    Likes Received:
    275
    Location:
    Bandung City
    [h=1]Forbidden[/h] You don't have permission to access /index.php on this server.
    Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
    [HR][/HR] Apache mod_qos/9.69 mod_fcgid/2.3.6 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 Server at suami-perkasa.com Port 80
     
  7. saladflorida

    saladflorida Super Hero

    Joined:
    Sep 1, 2010
    Messages:
    2,687
    Likes Received:
    313
    Location:
    Bandung-id

    solusinya gampang om, kalo traffic udah terlalu tinggi, sudah saatnya pindah dari shared ke VPS or Dedi :D
     
  8. gokslob

    gokslob Ads.id Fan

    Joined:
    Mar 27, 2010
    Messages:
    102
    Likes Received:
    0
    hostnya masi ngasi kesempatan untuk cukup pasang cache aja gan,, dicoba dululah.. :D
     
  9. saladflorida

    saladflorida Super Hero

    Joined:
    Sep 1, 2010
    Messages:
    2,687
    Likes Received:
    313
    Location:
    Bandung-id
    wah padahal kemaren pas ada promo black friday bisa dapet 80% OFF tuh, mayan VPS rasa shared :D
     
  10. mp3online

    mp3online Super Hero

    Joined:
    Jul 19, 2011
    Messages:
    2,228
    Likes Received:
    294
    Location:
    jakarta
    kalau pakai sistem cache kira-kira iklan adsense ikut kecache gak ya?
    kalau kecache bisa berabe tuh terutama kalau iklan yang kecache itu iklan yang udah habis duitnya dan gak seharusnya nungul lagi di halaman web
     
  11. suriemie

    suriemie Ads.id Pro

    Joined:
    Sep 15, 2006
    Messages:
    404
    Likes Received:
    53
    adsense ke cache scriptnya bukan iklan yg nongolnya, jadi ga masalah. tetep keluar iklan yg aktual.
     
  12. xrvel

    xrvel Super Hero

    Joined:
    Oct 21, 2007
    Messages:
    2,873
    Likes Received:
    947
    Location:
    Di sini
    Makin banyak cache, pemakaian space makin bengkak.
    operasi baca-file juga cukup berat lho, walau tentu aja gk seberat kalo baca dari database langsung.
     
  13. gokslob

    gokslob Ads.id Fan

    Joined:
    Mar 27, 2010
    Messages:
    102
    Likes Received:
    0
    ane udah coba terapin tapi masih lom berhasil gan,,

    file percobaan yg udah ditambahin kode itu ane buka, trus ane revisi dan buka lagi,
    munculnya versi yg revisi, bukan yg lama. berarti fungsi cachenya lom jalan.

    trus di bagian bawah halaman muncul pesan error:

    Warning: fopen(cache/.html) [function.fopen]: failed to open stream: No such file or directory in /home/xxx/public_html/xxx.php on line 572

    Warning: fwrite(): supplied argument is not a valid stream resource in /home/xxx/public_html/xxx.php on line 576

    Warning: fclose(): supplied argument is not a valid stream resource in /home/xxx/public_html/xxx.php on line 580

    mungkin ada file yg perlu dibikin n diaplod dulu ato gimana yak?
    ane betul2 gak mudeng nih soal beginian,, :(

    bigimana nih mastah2 programmer,, bantuin ane dong..
    (berbayar juga gak apa2)
     
  14. gembel-intelek

    gembel-intelek Lurker

    Joined:
    Mar 29, 2009
    Messages:
    4,341
    Likes Received:
    907
    Location:
    New Coral
    bikin folder cache di root

    tambahin di atas header

    PHP:
    <?php
    $interval 
    60 60//1 jam
    $filename "cache/".base64_encode(basenamertrim$_SERVER["REQUEST_URI"], '/' ) )).".cache";
    if ( 
    file_exists$filename ) && (time() - $interval) < filemtime$filename ) ) {
        
    readfile$filename );
        exit();
    }
    ob_start();?>
    tambahin di bawah footer

    PHP:
    <?php
    $buff 
    ob_get_contents();
    $file fopen$filename'w' );
    fwrite$file$buff );
    fclose$file );
    ob_end_flush();
    ?>

    harusnya sih bisa :D
     
  15. gokslob

    gokslob Ads.id Fan

    Joined:
    Mar 27, 2010
    Messages:
    102
    Likes Received:
    0

    tiga pertanyaan gan,,

    - di root itu berarti sejajar dengan public_html ya gan?

    - foldernya kosong aja tanpa file apapun?

    - tambahin di atas footer dan di bawah header itu maksudnya di bagian paling atas
    dan paling bawah file halaman yg mo kita cache atau di header.php dan footer.php gan?
     
  16. gembel-intelek

    gembel-intelek Lurker

    Joined:
    Mar 29, 2009
    Messages:
    4,341
    Likes Received:
    907
    Location:
    New Coral
    - iya, jadi ntar domain.com/cache
    - kosong
    - kalo mau header ma footerna pake metode include trus mo cache halaman tertentu, taruh di masing2 halaman yg mau dicache. kalo mau cache semua halaman, taruh diatas header.php ama dibawah footer.php
     
    gokslob likes this.
  17. gokslob

    gokslob Ads.id Fan

    Joined:
    Mar 27, 2010
    Messages:
    102
    Likes Received:
    0
    alhamdulilah,, berhasil di file percobaan :)

    foldernya berarti bukan sejajar public_html ya gan, tapi anaknya
    sekarang mo contact host dulu minta supaya dibuka lagi, mudah2an lancar

    makasi banget utk smua agan2 yg udah coba bantu ane,,
    untuk agan gembel-intelek, mo membership gratis gak? pm yah,, :D


    THREAD CLOSED
     
  18. vick2d

    vick2d Newbie

    Joined:
    Sep 17, 2011
    Messages:
    29
    Likes Received:
    1
    sistem cache buat apaan ?
     
  19. metagenesis

    metagenesis Super Hero

    Joined:
    May 1, 2010
    Messages:
    824
    Likes Received:
    133
    tread aku sambung lg ya gan, kenapa setelah

    $buff = ob_get_contents();
    $file = fopen( $filename, 'w' );
    fwrite( $file, $buff );
    fclose( $file );
    ob_end_flush();

    aku include iklan.php lalu foot.php tapi ketika di load cachenya itu tidak muncul hanya halaman sebelum
    $buff = ob_get_contents();
    $file = fopen( $filename, 'w' );
    fwrite( $file, $buff );
    fclose( $file );
    ob_end_flush();
    yang muncul
     
  20. gold1994

    gold1994 Newbie

    Joined:
    Jan 21, 2013
    Messages:
    27
    Likes Received:
    1
    nyimak nyimakkkk
     

Share This Page