boardom Forum Index boardom
b2 message board
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

req: generating static HTML pages
Goto page 1, 2  Next
 
Post new topic   Reply to topic    boardom Forum Index -> Hacks
View previous topic :: View next topic  
Author Message
fplanque



Joined: 22 Dec 2002
Posts: 53
Location: Montpellier, South of France

PostPosted: Mon Dec 23, 2002 2:48 pm    Post subject: req: generating static HTML pages Reply with quote

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 Smile
Back to top
View user's profile Send private message Visit poster's website
scrazynet11



Joined: 18 Nov 2002
Posts: 41
Location: Rio de Janeiro, Brazil

PostPosted: Mon Dec 23, 2002 8:52 pm    Post subject: yours Reply with quote

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
View user's profile Send private message Visit poster's website AIM Address
cjc



Joined: 24 Dec 2002
Posts: 146
Location: New York

PostPosted: Tue Dec 24, 2002 4:37 am    Post subject: Reply with quote

If you have access to a text-based browser on the unix side, you can do something along the lines of:

Quote:
/usr/bin/lynx --source http://www.example.com/blog/index.php > /var/www/html/blog/index.html


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
View user's profile Send private message Visit poster's website
fplanque



Joined: 22 Dec 2002
Posts: 53
Location: Montpellier, South of France

PostPosted: Tue Dec 24, 2002 11:56 am    Post subject: PHP only Reply with quote

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
View user's profile Send private message Visit poster's website
macshack



Joined: 17 Jul 2002
Posts: 1204
Location: Phoenix, Az

PostPosted: Tue Dec 24, 2002 5:33 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
GthicFury



Joined: 13 Dec 2002
Posts: 13
Location: Miami, FL

PostPosted: Tue Dec 24, 2002 5:33 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
alex_t_king



Joined: 09 Oct 2002
Posts: 194

PostPosted: Wed Dec 25, 2002 9:08 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger
macshack



Joined: 17 Jul 2002
Posts: 1204
Location: Phoenix, Az

PostPosted: Wed Dec 25, 2002 4:51 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
fplanque



Joined: 22 Dec 2002
Posts: 53
Location: Montpellier, South of France

PostPosted: Sun Dec 29, 2002 2:56 am    Post subject: a test script Reply with quote

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... Razz

Anyway, apart from that, do you think there might be some security issues with the script above?

Thanx Smile
Back to top
View user's profile Send private message Visit poster's website
macshack



Joined: 17 Jul 2002
Posts: 1204
Location: Phoenix, Az

PostPosted: Sun Dec 29, 2002 4:23 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
fplanque



Joined: 22 Dec 2002
Posts: 53
Location: Montpellier, South of France

PostPosted: Sun Dec 29, 2002 3:00 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
macshack



Joined: 17 Jul 2002
Posts: 1204
Location: Phoenix, Az

PostPosted: Mon Dec 30, 2002 7:44 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
zuluman



Joined: 02 Dec 2002
Posts: 3

PostPosted: Wed Jan 22, 2003 1:50 pm    Post subject: create static page Reply with quote

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
View user's profile Send private message
dtdgoomba



Joined: 05 Aug 2002
Posts: 179
Location: Cambridge, MA

PostPosted: Wed Jan 22, 2003 10:08 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
wjc



Joined: 18 Oct 2002
Posts: 9
Location: twin cities, mn, usa

PostPosted: Mon Feb 03, 2003 8:35 pm    Post subject: also, check your b2config Reply with quote

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
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    boardom Forum Index -> Hacks All times are GMT + 1 Hour
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB 2 © 2001, 2002 phpBB Group