Archived

This topic is now archived and is closed to further replies.

CProgrammer

php and forum programming

Recommended Posts

I know one would usually use MySql to store the forum data. But what speaks against using text files or binary files? Is it only the speed, cause it really isnt very slow? -CProgrammer

Share this post


Link to post
Share on other sites
My guess would be complex data management.

______________________________________________________________
The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ
MySite
______________________________________________________________

Share this post


Link to post
Share on other sites
you can use text or binary files but when your forums get large and complicated you''ll end up writing your own version of mysql (effectively) anyway. So why not use it from the beginning?

Share this post


Link to post
Share on other sites
MySQL is highly optimized, and will be alot faster at searching certain entries as opposed to a search trough a custom file format. Furthermore, when you create your own format, you would have to create some sort of editor for it too (using notepad to edit forum-data isn''t really the best solution) and if you are planing to add more "fields" to your file-format, you are going to face some major editing, whereas in mysql, this would only take a few lines of SQL.

Speed is certainly one of the main issues.
Size is another main issue. If you load a custom file, some might copy the whole file into memory, to save speed, so this would mean, your file format has a maximum file size, equal to the memory you have (actually it''s far less than that, because you would never get 100% of the memory assigned to your application for use, but anyways). To overcome the size issue, you would need to write some highly optimized Assembly routines to access the hard drive fast enough, but since your only possibility is PHP (which is in no way capable of accessing files as fast as raw machine code) you once again face the speed issue.

Furthermore, when it comes to Server-applications, it is almost always a speed issue (the fastest applications, win).

That''s my guess why most forums use mysql.

Yet for stuff like Guestbooks, text files might be a good option.

Share this post


Link to post
Share on other sites
Having written a forum using PHP and mySQL, I belive I can speak from expirence. There are some things you would Have to program in order to get it to work. Things that mySQL already has. If you want to attempt it as a learning expirence, great. However. Using $query = "SELECT * FROM forum WHERE start=1 ORDER BY ''group'' DESC"; although it could be coded fairly easily in php, is simply more readable and faster to code than opening a file, selecting entries, and ordering them.

Share this post


Link to post
Share on other sites
Yes a flat file system will perform MUCH better than MySQL (for easy queries). But it will be terribly complicated to get it right. AND when you come to difficult queries, which MySQL can optimise simply by a one-time operation of adding a few indexes, your custom data engine will need a lot of work to get right.

Also, when you come to change the structure of your database, you will need to write lots of migration tools etc; if you have more than one installation (in the world), you will need to ensure that it does version checking on its datafiles to maintain consistency.

It all boils down to, they have solved the most awkward problems for you. Yes, it''s much less efficient to use MySQL than do it yourself, but it will save an ENORMOUS amount of effort.

SQL is not perfect for writing queries, but it''s a lot better than trying to code a custom search engine for your binary file format.

Also I think if you compare the performance of MySQL with any other client-server based RDBMS, it will still seem quite fast*

Mark

* depending on your application and how you use it obviously. The only results to be trusted, ever, are real benchmarks from real users using a real system.

Share this post


Link to post
Share on other sites
Well looking at the posts I''d say MySql for complexity and maintainability.
However if the forum is not too complex and one has the time text or binary based is faster.

By the way I already wrote my text-based forum. I''m just wondering wether I should rewrite.
Oh and to the file size limits, I did it like in gamedev. 20 posts per page.
I then just made each page a file. Plus one could limit the size of a post for security.
Each user gets a file with his information which is parsed with a stringtokenizer.
And to make new posts appear in the beginning I have a file that holds the order.
Well theres a couple more features in there, but it''s not all too complex although I will further update it, which shouldn''t be too bad since it''s all OOP based.
So for a project with not too much complexity would you guess say I stick with text-based?

-CProgrammer

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Help! a file per page! at best you''ll very rapidly end up with a very cloged file system at the best!

If you ever intend it to be used I''d really suggest using a database solution.

Share this post


Link to post
Share on other sites
quote:
Original post by Anonymous Poster
Help! a file per page! at best you'll very rapidly end up with a very cloged file system at the best!

If you ever intend it to be used I'd really suggest using a database solution.


Could you be a bit more specific as to where the problem is. Why would having many files be an issue? Do webspace providers limit the number of files or why?
Besides this is going to be a private forum, so there won't be near as many posts as in GameDev.
But i'm still interested in the details.
-CProgrammer

[edited by - CProgrammer on April 4, 2004 12:56:08 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by CProgrammer
Could anybody elaborate on why a file per page is such a disaster?
Do you allow posts to be deleted? What happens when a post on page 6 (of 21) gets deleted; do all subsequent pages get reordered, and consequently all pages from 6 to 21 get rewritten?

How do you index threads? How do you choose filenames? How about moving threads? Moderators on GDNet frequently say something like "Wrong forum. Moved to Help Wanted." and, presto!, the thread is moved to Help Wanted. What then?

Did you know that GDNet''s forum has a pagesize parameter? That''s right, you can actually view any number of posts per page you want. How do you give someone that functionality using the file-per-page system? Then there''s the overhead, though small, of each file. A system INODE (on Unix-like OSes) gets consumed per file (and there''s only a couple billion of ''em); if your forum sticks around for a while, you might find that while capacity has not been reached (say, because of a profusion of one-post pages), you can''t create any more files.

It''s inelegant, there are a lot of special cases to consider, and it''s an unproven mechanism for handling volume. Go with the solution that backs many significant efforts. You''ll be more at peace in the long run.

Share this post


Link to post
Share on other sites