SitePoint Sponsor |
|
User Tag List
Results 1 to 9 of 9
Thread: speeding up site
-
Sep 2, 2001, 23:52 #1
- 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>";
PHP Code:<html>
here is some text--- 123456789
</html>
-
Sep 3, 2001, 03:58 #2
- 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
-
Sep 3, 2001, 17:51 #3
- 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 , 0 , $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+1 );
$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 );
?>
-
Sep 4, 2001, 01:04 #4
- 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)
-
Sep 4, 2001, 14:39 #5
- 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
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?
thanxLast edited by slighltywhacked; Sep 4, 2001 at 14:41.
-
Sep 5, 2001, 03:57 #6
- 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!
-
Sep 5, 2001, 08:47 #7
- 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?
-
Sep 6, 2001, 02:09 #8
- 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!
-
Sep 6, 2001, 18:13 #9
- 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