php3-list | 199807
Date: 07/24/98
- Next message: George Brown: "Re: [PHP3] just the file_name from PHP_SELF"
- Previous message: Mario Filipe: "[PHP3] just the file_name from PHP_SELF"
- In reply to: Colin Viebrock: "RE: [PHP3] Off Topic - Phorum - Multil Level Threading of Messages"
- Next in thread: p.m: "[PHP3] message form in PHP..whats most efficient?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Thu, 23 Jul 1998, Colin Viebrock wrote:
> I've written a very nice threaded message board in PHP3.
>
> Basically, you need an additional field in the database of messages:
> parentID (I assume each message already has an ID field).
>
> The function to show the messages, threaded, looks something like (pseudo
> code):
>
>
> function showMessages($parent) {
> select * from message_table where parentID = $parent;
> if numrows!=0:
> print message date, title, etc.;
> showMessages(ID);
> endif;
> };
>
> So, the function calls itself with the ID of the current message. And when
> you want to show stuff the first time, just call the function with "0"
> (assuming that all messages at the start of a thread have a parentID of "0").
>
This will work (even better: it's the only clean way to do it :) , but
there's a performance problem here, because of the possibly large number
of database requests this will produce.
I'm currently working on a project which includes a message board
functionality, and I came up with the following design to speed up
requests for entire tree's, I'm not saying it's pretty though :)
the table look's like:
create table objecttree (
id int primary key,
parent int not null,
name varchar(16) not null,
path varchar(127) not null,
startdate date,
enddate date,
object int not null )
(the dates are not needed for this example but i've kept them in anyway..)
now, the id and parent integers work exactly as you've said earlier, but
in addition everything in the tree has a name and a path, which behave
like a filepath and filename. Thus you can have a messge with name '001'
and path '/messages/001/'. Replies to this message will be numbered
starting from 001 again with path='/messages/001/001/' and name '001'
thus the next reply to the original is '/messages/001/002/'.
Then a second message on the toplevel will be '/messages/002/'.
Now it's simple to get he database to spew forth all message in the
correct order with the following query:
select * from objecttree where path like '/messages/*' order by path;
which will result in:
/messages/001/
/messages/001/001/
/messages/001/002/
/messages/002/
the problem(s) with this design are the fact that to index the path (under
mysql) it mustn't be longer than 127 characters... any deeper levels can't
be made. Furthermore, to use the alfabetical sorting you need to pad the
message id's with 0's, which mens that in this example you can't have more
than 999 messages in one level, but you could use 00001 instead and get
99999 messages and still get to 20 levels of reactions...
Well, this is the best I could think of to prevent recursive database
queries which can get you in to 'need-a-faster-server' problems very
quickly. It's a tradeoff though, the design does create boundaries to the
number of messages and the depth of reactions to a messages. But then
again, the longest thread I've ever seen in a newsgroup was 'The Longest
Thread Ever (tm)' and I think it's a win that this can't happen
with this design ;-)
Anyway, you can prevent this problem by using the
slashdot like approach, start a new message thread from one special
article. Sort these special articles by date or something and remove them
(or move them to an 'old news' page) after some time. This way it's not
too probable that you'll hit the barrier :)
If you really really want the no-boundaries and cleanliness of the first
design, but you still need the speed of my 'hack', there's probably one
way to do it, build your own specialized database engine for threaded
messages. Build it in C or something, and then run it as a persistent cgi
or fastcgi or maybe even a special daemon.
regards,
Auke van Slooten
-- PHP 3 Mailing List http://www.php.net/ To unsubscribe send an empty message to php3-unsubscribe <email protected> To subscribe to the digest list: php3-digest-subscribe <email protected> For help: php3-help <email protected> Archive: http://www.php.net/mailsearch.php3
- Next message: George Brown: "Re: [PHP3] just the file_name from PHP_SELF"
- Previous message: Mario Filipe: "[PHP3] just the file_name from PHP_SELF"
- In reply to: Colin Viebrock: "RE: [PHP3] Off Topic - Phorum - Multil Level Threading of Messages"
- Next in thread: p.m: "[PHP3] message form in PHP..whats most efficient?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

