php and forum programming

Started by
11 comments, last by CProgrammer 20 years ago
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
Advertisement
My guess would be complex data management.

______________________________________________________________
The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ
MySite
______________________________________________________________
______________________________________________________________________________________The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ"So. Any n00bs need some pointers? I have a std::vector<n00b*> right here..." - ZahlmanMySite | Forum FAQ | File Formats______________________________________________________________________________________
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?
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.

Not just that, MySQL also handles transactions and such. Just you try writing a text-based system that allows 50 to update a forum simultaneously without headaches.
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.
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.
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
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.
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]

This topic is closed to new replies.

Advertisement