Pros and cons of page buffering.

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Pros and cons of page buffering.

Post by Gen-ik »

This is basically one of those "is this a good idea" questions.

I'm playing around with a new method of developing my websites which uses the tried and tested method of including various data into the page(s) when needed.

Something I am thinking about doing is 'preloading' some of the more widely used pages/includes into a session when the session is first created, so that the 'preloading' only needs to be done once when the session first gets created.

For example let's say I have a news.php file which gets included into the page whenever someone goes to the news section.. and instead of using include() each time all I do is echo() the session variable which contains the 'preloaded' news.php code.


Has anyone tried this before, or does anyone have any valid pros/cons about this method of development?


Thanks in advance.
jmarcv
Forum Contributor
Posts: 131
Joined: Tue Jul 29, 2003 7:17 pm
Location: Colorado

Post by jmarcv »

Never used sessions. Hear they are easy, but have my own way of handling them. But as I understand it, its basically a super cookie. Your idea sound plausible enough. I guess only cons I see are the obvious 'up to minute' data loss, but in your case that doesn't seem to be an issue. Only other glitch I see is data size. What is session max? Also, do sessions transfer that data to every page wether needed or not, in which case to you choke bandwidth with unnecessary crap? If that is the case, maybe best to create a temporary file and just pass the name in the session and include the temporary file when you need it?
pootergeist
Forum Contributor
Posts: 273
Joined: Thu Feb 27, 2003 7:22 am
Location: UK

Post by pootergeist »

a session is still stored as a file (normally in /tmp) and thus would still need to be read at each page load. the more data you sling in there, the more that needs to be read. the only part of a session that is sent to the client is the id# - which is sent as a cookie/post/get - when a http request arrives the php parser looks in /tmp for a session file with the same id# and pretty much includes() that into the active script.

if you think include is too slow then cache the entire html at set intervals (maybe every ten seconds) and header redirect if the file exists.

if the include file is just html, then using readfile($file_ref); would be slightly faster than include. readfile() turns off the php interpreter and just outputs to browser/buffer
Post Reply