How to Create/Open files in PHP

Discussion in 'PHP' started by WebDivx, Nov 15, 2006.

  1. #1
    I am sort of trying to edit a PHP script and wanted to know how I can have the data go into a file instead of the mysql database.

    Ok, so Digital Point is using the vBulletin forum script. Our forum posts are typed in a box and are saved in a MySQL database.

    How do I edit this kind of thing so that instead of saving data in the MySQL database, a new file on my server is created (like a .txt or .html file) and then that file opens when you view the post.

    So pretty much I am just wondering how I can have my forum work like a regular forum, but save and access the forum posts from stored files (like .txt or .html) insted of the MySQL database.

    Help is really appriciated!
     
    WebDivx, Nov 15, 2006 IP
  2. Kisiel

    Kisiel Peon

    Messages:
    12
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    It will be hard to change existing forum into the file system. The best way is to write your own forum working on files. If you can't php use google for some free boards. There is plenty of them
     
    Kisiel, Nov 15, 2006 IP
  3. lbalance

    lbalance Peon

    Messages:
    381
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #3
    what advantage would saving the data in text files serve?

    it will be a pain to search the forums

    why not write a script to pull data from mysql and write that data to text files
     
    lbalance, Nov 15, 2006 IP
  4. WebDivx

    WebDivx Peon

    Messages:
    212
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    well i am not using an existing board..existing meaning active, but like a fresh installed one. I don't want everything to be written in a file, just the forum posts.


    Well, from my understanding, the advantage is that a huge database does not have to load every time to view a small topic. Instead, small files pertaining to a topic of choice opens. this saves CPU power and makes a site load fasters.

    Anyways searching wouldn't be a problem. a Script called cute news, a news posting script (http://www.cutephp.com) saves news in files instead of a MySQL database. Also, the search feature is pretty nice and easy to use like a forum search.
     
    WebDivx, Nov 15, 2006 IP
  5. lbalance

    lbalance Peon

    Messages:
    381
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #5
    if using a database for a forum is not efficiant, then i would think that the forum software companies would change their code.

    can you imagine how many txt files you would end up on the server? that would slow it down as well.
     
    lbalance, Nov 15, 2006 IP
  6. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #6
    The entire database isn't opened up when reading a particular topic. Forget the forum software companies getting this right, don't you think the database companies themselves have thought about this and got it right?

    Databases are indexed and all sorts of crazy things so that access is not hindered. In fact, with a large enough number of topics I would guess that 9 times out of 10 the DB is faster than most filesystems.
     
    TwistMyArm, Nov 15, 2006 IP
  7. maiahost

    maiahost Guest

    Messages:
    664
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Well, file repositories were dropped a long time ago. Maybe you should ask yourself why? When you have all your data organized and easily managed it's going to take a lot less to perform a search insted of a file system. Imagine a forum with 30K posts and 30k files .... now how would you search that ?
     
    maiahost, Nov 15, 2006 IP
  8. WebDivx

    WebDivx Peon

    Messages:
    212
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #8
    I guess all your logic about databases make sense. But a 500 MB database, for example, thats outrageous and hard to manage. It still, you know, is hard to comprehend (sorry if I am an idiot) that one large file would not be more of a burden for a server.

    I guess my other reason for asking this is with my current site I run a MySQL database for news that is only 10 MB and my host said that it is using too many CPU resources. About 20% of the entire server. I'm on a shared server, but even if I'd upgrade to VPS/VDS or dedicated, if I was to have forums it would use a hell lot more of the CPU power since forums have more and in some cases longer entries then when you have a news script.
     
    WebDivx, Nov 15, 2006 IP
  9. ajscottsr

    ajscottsr Peon

    Messages:
    388
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    0
    #9
    WebDivx,

    Your thinking about databases are all wrong. Remember, MySQL is a relational database. A 500 MB database should actually be a bunch of smaller files. Even if there is a single table at 500 MB, if the server is setup properly and has sufficient ram and CPU time, it shouldn't be a problem.

    My experience has been that when people are experiecing problems with database performance, its either because the machine is overloaded (very common in shared hosting environments), unreasonably limited (very common in VPS environments) or a very poorly designed database (like a full index on a large field with a large number of rows).

    If you use a predesigned application like PHPBB or VBulletin, a 10MB database should be no problem, even in an overloaded shared hosting environment. If this is home grown, try looking at your indexes and table structure. If you remove the index, you'll slow searches down considerably and increase load at search time but save a lot of load at the time posts are made to the board. On the other hand, if you get a lot of searches, the indexes will slow down the new posts slowly but make searches a lot faster (when done right anyway).

    Hope the info helps.
     
    ajscottsr, Nov 15, 2006 IP
  10. WebDivx

    WebDivx Peon

    Messages:
    212
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #10
    hey thanks for the info. I took a look at my database and i have a lot of rows. The script I use just makes a row for every transaction.

    So I am using 4images in this particular database. Everytime I add an image to my site a new row corrosponding to that image is made.

    How do I stop this, and how to I get rid of the thousands of existing rows I have already created without doing it manually, and what effects, if any, would it have?
     
    WebDivx, Nov 16, 2006 IP
  11. ajscottsr

    ajscottsr Peon

    Messages:
    388
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Sorry, I can't answer that because I'm not sure why the script is adding rows and what they are used for. Deleting them could have various effects depending on how they are used or if they are used at all.

    Is the image itself being stored or just a file name or location?
     
    ajscottsr, Nov 16, 2006 IP
  12. WebDivx

    WebDivx Peon

    Messages:
    212
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #12
    just the file and location. here is, i guess an excerpt, from the database. it looks exactly like this, except, each INSERT INTO is the start of a new row. The forums don't have enough space, so it looks like image_media_file and image_rating is also a new row (but its not like stated above)

    INSERT INTO images_images (image_id, cat_id, user_id, image_name, image_description, image_keywords, image_date, image_active, image_media_file, image_thumb_file, image_download_url, image_allow_comments, image_comments, image_downloads, image_votes, image_rating, image_hits) VALUES (11625, 225, 1, 'Picture017', '', '', 1152486432, 1, '017.jpg', '017.jpg', '', 1, 0, 0, 0, '0.00', 23);
    INSERT INTO images_images (image_id, cat_id, user_id, image_name, image_description, image_keywords, image_date, image_active, image_media_file, image_thumb_file, image_download_url, image_allow_comments, image_comments, image_downloads, image_votes, image_rating, image_hits) VALUES (11626, 225, 1, 'Picture018', '', '', 1152486432, 1, '018.jpg', '018.jpg', '', 1, 0, 0, 0, '0.00', 91);
    INSERT INTO images_images (image_id, cat_id, user_id, image_name, image_description, image_keywords, image_date, image_active, image_media_file, image_thumb_file, image_download_url, image_allow_comments, image_comments, image_downloads, image_votes, image_rating, image_hits) VALUES (11627, 225, 1, 'Picture019', '', '', 1152486432, 1, '019.jpg', '019.jpg', '', 1, 0, 1, 0, '0.00', 33);
    INSERT INTO images_images (image_id, cat_id, user_id, image_name, image_description, image_keywords, image_date, image_active, image_media_file, image_thumb_file, image_download_url, image_allow_comments, image_comments, image_downloads, image_votes, image_rating, image_hits) VALUES (11628, 225, 1, 'Picture020', '', '', 1152486432, 1, '020.jpg', '020.jpg', '', 1, 0, 0, 1, '3.00', 45);
     
    WebDivx, Nov 16, 2006 IP
  13. ajscottsr

    ajscottsr Peon

    Messages:
    388
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    0
    #13
    Chances are, deleting rows from the database would at a minimum leave you with broken images all over your forum and at a maximum generate errors and make the site unusable.

    Do you have an option in your software to prune or purge older threads? That might help you to scale down the database some.

    If its writing those entries to the database, I would assume that its also referring to that information elsewhere (otherwise what would be the point of writing them).
     
    ajscottsr, Nov 16, 2006 IP
  14. WebDivx

    WebDivx Peon

    Messages:
    212
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #14
    nope, no options to scale down the database... :(
     
    WebDivx, Nov 16, 2006 IP
  15. ajscottsr

    ajscottsr Peon

    Messages:
    388
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    0
    #15
    Scale up the server, faster CPU, lots more memory, raid configured SCSI drives, all sorts of options are available.

    You could try to optimize the MySQL database. You may have indexes that are not necessary that are increasing load.

    Or try a different script that is more scalable.
     
    ajscottsr, Nov 17, 2006 IP
  16. WebDivx

    WebDivx Peon

    Messages:
    212
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #16
    how do you "optimize" the database? i really want to do that, but dont know how. my host said that as well but they are not helpful. can you please tell me, how to optimize my database? Is there a program that does this or something? thanks 4 the help!
     
    WebDivx, Nov 17, 2006 IP
  17. legend2

    legend2 Well-Known Member

    Messages:
    1,537
    Likes Received:
    74
    Best Answers:
    0
    Trophy Points:
    115
    #17
    writing to a file is very resource consuming. such an IO is a disaster for large sites which require constant updates to the file.
     
    legend2, Nov 19, 2006 IP
  18. ajscottsr

    ajscottsr Peon

    Messages:
    388
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    0
    #18
    Well, there's a command in MySQL that does some basic clean up (see MySQL documentation), however the topic of optimizing a database is something that could scarecly fit in a book. You could easily spend an entire semester (or two or three) in college studying that topic. Not something I can give you a quick fix for.

    Contact the author of the forum software and describe the problem you are experiencing. Chances are other users are experiencing the same problem and there may already be a solution for it.

    If not..., try other forum products. I personally like vBulletin. It's not the cheapest, but its very scalable and can handle extremely large/busy sites. Notice the tag at the very bottom of this page. No doubt its probably customized to some degree for this site and on some very heavy duty hardware, but it gives you an idea of what it can handle.
     
    ajscottsr, Nov 21, 2006 IP