Jump to content

fwrite() or MySQL


onlyican

Recommended Posts

Hey people.

 

Been a while since I posted in here.

Been too busy.

 

Anyway, I am after Advice from the brains.

 

I have a website which runs a lot of MySQL queries.

As most big complex sites do.

 

This site has a CMS (Content Management System)

So in Admin, the user can edit the content of the page, then Store this as a preview, either Save changes, or if User does not have Privileges, someone who does can come along and Approve changes.

 

The MySQL Table holds the Users ID of the User who last updated the page content.

 

But we want to log the Users ID for EVERY change made, not just the last change.

 

2 Options:

Create new Table, to log the entries

Use a file, write to the file every change, and user ID

 

What is quicker and easier on the server load.

I would like to know why, so please don't just say MySQL or File.

Link to comment
Share on other sites

MySQL. 

 

The file will be faster at first, but as it grows in size it will get more cumbersome to use.  Every time it gets written to the OS has to open the whole file, then append to it, then close it.  If that file is several MB in size, then that can eat system resources.  Additionally, you will encounter a problem with file access...what happens when PHP, which is multi threaded, tries to access that file with 2 or more of it's threads at the same time?

 

Additionally, using the file makes it much much slower and more difficult to do the associations when you want to look at the history for a particular piece of content or user.  You are already going to have to use a join in your user table to get the user name when you are doing a "history", so, rather than having to read your file, then pull the relevant information, you can do a single query with a join.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.