SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Guru
    Join Date
    Apr 2001
    Location
    BC, Canada
    Posts
    630
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    speeding up site

    Our site is beggining to slow down because of all the queries to databases, updates, ect...

    seen as how the content is only updated about 3 times a day is it possible to make a static version of the updated page... yeah sounds confusing huh?

    k.. lets u say u have the page "updated.php3"
    and this page queries the database and always is up to date, as soon as the database is updated.. regulary this would be our home page. But to releive some stress off the database could we have a script copy the html that "updated.php3" produces, pastes it into another file say "index.shtml"

    so maybe "updated.php3" has something like this
    PHP Code:
    $blah=time();
    echo
    "<html>heres is some text--- $blah</html>"
    then after a script is run, it would create index.shtml and all that would be in it is

    PHP Code:
    <html>
    here is some text--- 123456789
    </html
    kinda see what I mean? creates a file from the output of the other one

  2. #2
    SitePoint Enthusiast smashway's Avatar
    Join Date
    Sep 2001
    Location
    Lausanne, Switzerland
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think you could be interested in reading this article http://www.zend.com/zend/art/scriptcaching.php . By the way, they have excellent articles, tutorials and columns!

    Hope this helps,

    Smash

  3. #3
    SitePoint Guru
    Join Date
    Apr 2001
    Location
    BC, Canada
    Posts
    630
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanx for hte link
    but I am having trouble using the script

    It isnt doing anything

    Im probaly doing something wrong..heres what I got


    PHP Code:
    <?php 

    // example caching script 

    // get the static HTML file's location 

    $cache_file $REQUEST_URI

    // find out the URL of the dynamic script 
    // which creates the static file. 

    $maker_URL str_replace "/cache/" "/" $cache_file ); 
    $maker_URL str_replace ".html" "" $maker_URL ); 
    $last_slash strrpos $maker_URL "/" ); 

    // find out the creating script's name 
    // and make sure it exists. 

    $script substr $maker_URL $last_slash ) . ".php"
    $find $DOCUMENT_ROOT $script
    if ( !
    file_exists $find )) { 

        
    // if the file does not exist, show a 
    // File Not Found error - 
    // echo ("Couldn't find $REQUEST_URI"); 
    // you can put a nice page here... 
        
    exit; 
    // but don't forget to exit ! 


    // now parse the query string 
    // here, "_" means "=" and "__" means "&" 
    // These rules are just personal preferences 

    $query_str "?" substr $maker_URL $last_slash+); 
    $query_str str_replace "__" "&" $query_str ); 
    $query_str str_replace "_" "=" $query_str ); 

    // and now create the full maker_URL 

    $maker_URL "http://www.sportskelowna.com/cache/uptodate.shtml"

    // open the maker script and read its output 

    $read fopen $maker_URL "r" ); 
    if ( !
    $read ) { 
        echo ( 
    "Could not open $maker_URL); 
        exit; 


    $HTML_output ""

    // read the HTML output while displaying it 

    while ($line fgets $read 256 )) { 
        
    $HTML_output.= $line
        echo 
    $line

    fclose $read ); 

    // finally, save the HTML output 
    // in a cache file. 

    $write fopen $DOCUMENT_ROOT $cache_file "w" ); 

    if ( !
    $write ) { 

    // you might not have permission 
    // to write in that directory. 

        
    echo ( "could not open $writefile for writing" ); 
        exit; 


    // lock the write file and 
    // write all the HTML into it 

    if ( !flock $write LOCK_EX LOCK_NB )) { 

    // for PHP version < 4.0.1 
    // change LOCK_EX to 2 

    echo ( "could not lock $writefile); 
        exit; 


    fwrite $write $HTML_output strlen $HTML_output ) ); 
    flock $write LOCK_UN ); 

    // release lock. For PHP version < 4.0.1 
    // change LOCK_UN to 3 

    fclose $write ); 
    ?>

  4. #4
    SitePoint Enthusiast smashway's Avatar
    Join Date
    Sep 2001
    Location
    Lausanne, Switzerland
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Maybe this one will seem easier
    It was the one I had in mind before giving the Zend one.

    By the way, phpbuilder is really useful (almost as sitepoint )
    Smash

    Check this thread and help me: click here!

  5. #5
    SitePoint Guru
    Join Date
    Apr 2001
    Location
    BC, Canada
    Posts
    630
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanx for recommending php builder

    I found one thing that worked pretty well on there

    this how its used
    login through telnet and use this

    PHP Code:
    lynx -source http://www.site.com/dynamic.php3 > static.html 
    worked perfectly
    now, I need that to be run every couple of hours. I talked to the server admin guy and he told me to create a "BASH script" and then use a cronjob to run it
    just wondering what a BASH script is? is it just a file that issues commands to the server? how do I create one? tutorials? or is it just a couple lines of code?


    thanx
    Last edited by slighltywhacked; Sep 4, 2001 at 14:41.

  6. #6
    SitePoint Enthusiast smashway's Avatar
    Join Date
    Sep 2001
    Location
    Lausanne, Switzerland
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hehe a bash script is like a .bat program for DOS. I don't even think you need to create that script

    at the prompt, you should type "man crontab", and read all the instructions. The command you'll want to set up would be the same one as to one you manually use (lynx -source http://www.site.com/dynamic.php3 > static.html) but this one will fork (=start) another instance of lynx each time the crontab script is run, eventually forcing you to reboot the machine or kill the lynx instances by hand. Like I said in another post, you could use crontab to enter a kill -9 command some minutes after starting lynx, but I belive there's an option which will quit lynx after some time (lynx -a ?, lynx -o ? Could anyone give some feedback here?)

    That's about it!
    Smash

    Check this thread and help me: click here!

  7. #7
    SitePoint Guru
    Join Date
    Apr 2001
    Location
    BC, Canada
    Posts
    630
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    "kill -9 command"

    does that just kill all instances of lynx?

  8. #8
    SitePoint Enthusiast smashway's Avatar
    Join Date
    Sep 2001
    Location
    Lausanne, Switzerland
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    man kill

    well actually you usually kill the Process ID (PID) of a program, for example "kill -9 2134". The PID can be found using the "ps aux" command, but you can also use alternate ways to kill a process, just try to have a look at the man page!
    Smash

    Check this thread and help me: click here!

  9. #9
    SitePoint Addict jamesbond's Avatar
    Join Date
    Feb 2001
    Location
    The Netherlands
    Posts
    256
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wouldn't it be possible to execute 'lynx -source http://www.site.com/dynamic.php3 > static.html' through php whenever you submit new content?

    By using the exec command: http://www.php.net/manual/en/function.exec.php

    For example something like this :

    if ($submit) {

    exec("lynx -source http://www.site.com/dynamic.php3 > static.html");

    }

    Haven't tried it, just wondering if it would work.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •