View previous topic :: View next topic |
Author |
Message |
fplanque
Joined: 22 Dec 2002 Posts: 53 Location: Montpellier, South of France
|
Posted: Mon Dec 23, 2002 2:48 pm Post subject: req: generating static HTML pages |
|
|
Hi. Does anyone know how to generate static HTML pages instead of having everything running as dynamic PHP ?
I am particularly thinking about the blog homepage, the one that is displayed by index.php with absolutely NO QUERY STRING. That one would be really cool to have in HTML.
Visitors would then first hit on index.html and get super fast access to latest posts... then if they want to get something more specific, they will hit on index.php?somequerystring...
Has someone seen some implementation like that somewhere?
Thanks  |
|
Back to top |
|
 |
scrazynet11
Joined: 18 Nov 2002 Posts: 41 Location: Rio de Janeiro, Brazil
|
Posted: Mon Dec 23, 2002 8:52 pm Post subject: yours |
|
|
take a look at coranto, it´s PERL written but it generates html as you want.
http://coranto.gweilo.org _________________ - Scrazynet
"To be or not to be, that´s the mothephuc**ing Question "
http://www.loukelicioso.net |
|
Back to top |
|
 |
cjc
Joined: 24 Dec 2002 Posts: 146 Location: New York
|
Posted: Tue Dec 24, 2002 4:37 am Post subject: |
|
|
If you have access to a text-based browser on the unix side, you can do something along the lines of:
This can be set in a cron job to run hourly, say. The web browser should be set up so that index.html would be chosen before index.php. |
|
Back to top |
|
 |
fplanque
Joined: 22 Dec 2002 Posts: 53 Location: Montpellier, South of France
|
Posted: Tue Dec 24, 2002 11:56 am Post subject: PHP only |
|
|
Thanx for your answers guys.
But the only thing I can execute on the server is PHP !!
There definitely must be a way to capture all generated output into a variable at the end of a script and then write this variable to a file.
(there was a way to do that in my old ColdFusion days anyway )
cjc, your solution is basically exactly what I would have done if the server had been under my control, except that I would probably have cron'd PHP to execute the file directly and filtered out the http headers before redirecting to a file |
|
Back to top |
|
 |
macshack
Joined: 17 Jul 2002 Posts: 1204 Location: Phoenix, Az
|
Posted: Tue Dec 24, 2002 5:33 pm Post subject: |
|
|
Hi,
Look at www.php.net for the function ob_start.
But I believe that this function can not be nested. It is used with in b2 to capture the output to the browser and then compress it with zlib.
michael e |
|
Back to top |
|
 |
GthicFury
Joined: 13 Dec 2002 Posts: 13 Location: Miami, FL
|
Posted: Tue Dec 24, 2002 5:33 pm Post subject: |
|
|
Hmm, I was just thinking of figuring a way to do this myself. Caching only the newest blog entries to a seperate *.inc file that would only update when a new entry is "blogged" - any search, previous/next functionality would still soley rely on the dB.
It would be a nice feature to have to reduce dB overhead. _________________ -= Eric |
|
Back to top |
|
 |
alex_t_king
Joined: 09 Oct 2002 Posts: 194
|
Posted: Wed Dec 25, 2002 9:08 am Post subject: |
|
|
Re: nesting ob_start()...
This is valid (or at least works for me):
Code: | <?
ob_start();
ob_start();
print("some string<br>\n");
$temp_1 = ob_get_contents();
ob_end_clean();
print($temp_1);
print($temp_1);
$temp_2 = ob_get_contents();
ob_end_clean();
print($temp_2);
?> |
The result will be:
some string
some string
This kind of nesting works for me... not sure if this was what you meant or not macshack. _________________ Yahoo! Messenger ID: alex_t_king |
|
Back to top |
|
 |
macshack
Joined: 17 Jul 2002 Posts: 1204 Location: Phoenix, Az
|
Posted: Wed Dec 25, 2002 4:51 pm Post subject: |
|
|
Hi alex_t_king,
Yes that is what I was concerned about. I just didn't take the time as you did to test it. Good to know and thank you.
If I remember correctly, the only thing that is not captured is the header() function calls. So this should satisfy the need to capture the "static" html.
A Merry Christmas and Joyous Holidays to all,
michael e |
|
Back to top |
|
 |
fplanque
Joined: 22 Dec 2002 Posts: 53 Location: Montpellier, South of France
|
Posted: Sun Dec 29, 2002 2:56 am Post subject: a test script |
|
|
Slowly recovering after Xmas, I made a little script I would call something like "makeindex.php":
Code: |
<?php
print "generating page...<br>";
ob_start();
require "index.php";
$page = ob_get_contents();
ob_end_clean();
print "writing to file...<br>";
$fp = fopen ("./index.html", "w");
fwrite($fp, $page);
fclose($fp);
print "done<br>";
?>
|
It almost does the job... but there is something like a nesting problem somewhere in the original include ("b2/blog.header.php"); ... or rather, it looks like there's a nasty output flush in there... I'll have to look into that a little closer...
Anyway, apart from that, do you think there might be some security issues with the script above?
Thanx  |
|
Back to top |
|
 |
macshack
Joined: 17 Jul 2002 Posts: 1204 Location: Phoenix, Az
|
Posted: Sun Dec 29, 2002 4:23 am Post subject: |
|
|
Hi,
Well I think I would put the script in a directory that is protected for one. Two I think I would write to a file then release the index.html then re-name the new file to index.html and even change the permissions on the file to read only. All after you are sure the file has been written correctly.
Obviously the web server has to be able to write to the file. Thus I think your open to some other user then being able to do the same thing. I think I'm correct on that. In any event, these are the kind of things to think about.
From a different view, I guess I question why this is necessary in the first place. Without compelling benchmarks to convince me otherwise, I think the load is relatively small on a typical weblog. IMHO.
Kind regards,
michael e |
|
Back to top |
|
 |
fplanque
Joined: 22 Dec 2002 Posts: 53 Location: Montpellier, South of France
|
Posted: Sun Dec 29, 2002 3:00 pm Post subject: |
|
|
Hi macshack,
Here's a demo of how slow things can get on a free hosting service: http://fplanque.free.fr/Blog/itTrends.php (if it happens to run in less than 10 seconds the first time, try a refresh )
Compare it to the static version: http://fplanque.free.fr/Blog/itTrends.html
This is unfinished test material, but you should get the idea
Another approach I am going to try is to flush output after each post... should make it less painfull for the user
Thanx for your comments on security. There's just one thing I'm not sure I understand right: what do you mean by "releasing the index.html" ?
-Francois PLANQUE
http://fplanque.com/ |
|
Back to top |
|
 |
macshack
Joined: 17 Jul 2002 Posts: 1204 Location: Phoenix, Az
|
Posted: Mon Dec 30, 2002 7:44 am Post subject: |
|
|
Hi fplanque,
Ok, I understand the "free" service thing, but this is a server/provider issue due to configuration constraints/parameters. BTW, when I used your links just before this post the difference in load times were very small.
Where my head was bout the "release the index.php" file was to minimize the possibility that the index file is not reachable or incomplete due some other issues and potentially to further reduce the chance that some other process would find a way to write to your index.php file (all this writing and such would be under the process of the server/php).
Regards,
michael e |
|
Back to top |
|
 |
zuluman
Joined: 02 Dec 2002 Posts: 3
|
Posted: Wed Jan 22, 2003 1:50 pm Post subject: create static page |
|
|
hi
simply create a cronjob with the following code:
0,30 * * * * /usr/bin/php -q /home/user/index.php > /home/usr/index.htm
This cronjob will run on the hour and every half an hour and generate a static version of index.php, called index.htm.
You will need to change the file locations to suit your hosting environment, but other than that, that is all you need do. (***The 'q' handle suppresses header information and allows the output of the html page. PS. Ensure your index.htm file has write permissions.***)
Next, edit your htaccess file and change the DirectoryIndex directive to point to index.htm
Cheers
BK |
|
Back to top |
|
 |
dtdgoomba
Joined: 05 Aug 2002 Posts: 179 Location: Cambridge, MA
|
Posted: Wed Jan 22, 2003 10:08 pm Post subject: |
|
|
Strangely, I've been learning php/cron stuff this week. If you have PHP as an an apache module on your server and not an executable, then you can't use the above in your cron. (I'm pretty sure). Here is a ref on it. Just do a search on google for cron/php. They all said the same thing pretty much..
http://www.htmlcenter.com/tutorials/tutorials.cfm/155/PHP/ |
|
Back to top |
|
 |
wjc
Joined: 18 Oct 2002 Posts: 9 Location: twin cities, mn, usa
|
Posted: Mon Feb 03, 2003 8:35 pm Post subject: also, check your b2config |
|
|
This trick works nicely, except that internal page links will likely break. On my site with index.html generated as above from the index.php, the archive links work, but the comment and category links don't, because they'll load as an URL like this:
http://www.fidean.net/b2/?p=83&c=1#comments
so, of course, the php isn't getting executed because it's loading index.html rather than index.php
monkeying around with the paths in b2config won't fix it - it'll take some deeper hacking if you're using kinds of links. |
|
Back to top |
|
 |
|