Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6389167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:22:13+00:00 2026-05-25T03:22:13+00:00

I have few scripts loaded by cron quite often. Right now I don’t store

  • 0

I have few scripts loaded by cron quite often. Right now I don’t store any logs, so if any script fails to load, I won’t know it till I see results – and even when I notice that results are not correct, I can’t do anything since I don’t know which script failed.

I’ve decided to store logs, but I am still not sure how to do it. So, my question is – what’s more efficient – storing logs in sql database or files?

I can create ‘logs’ table in my mysql database and store each log in separate row, or I can just use php’s file_put_contents or fopen/fwrite to store logs in separate files.

My scripts would approximately add 5 logs (in total) per minute while working. I’ve done few tests to determine what’s faster – fopen/fwrite or mysql’s insert. I looped an “insert” statement 3000 times to make 3000 rows and looped fopen/fwrite 3000 times to make 3000 files with sample text. Fwrite executed 4-5 times faster than sql’s insert. I made a second loop – I looped a ‘select’ statement and assigned it to a string 3000 times – I also opened 3000 files using ‘fopen’ and assigned the results to the string. Result was the same – fopen/fwrite finished the task 4-5 times faster.

So, to all experienced programmers – what’s your experience with storing logs? Any advice?

// 04.09.2011 EDIT –
Thank you all for your answers, they helped ma a lot. Each post were valuable, so it was quite hard to accept only one answer 😉

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T03:22:13+00:00Added an answer on May 25, 2026 at 3:22 am

    You can use a component such as Zend_Log which natively supports the concept of writers attached to the same log instance. In that way you can log the same message to one or more different place with no need to change your logging code. And you can always change your code to replace the log system or add a new one in a simple way.

    For your question I think that log to files is simpler and more appropriate if you (developer) is the only one who needs to read log messages.

    Log to db instead if you need other people needs to read logs in a web interface or if you need the ability to search through logs. As someone else has pointed out also concurrency matters, if you have a lot of users log to db could scale better.

    Finally, a log frequency of 5 messages per minute requires almost no cpu for your application, so you don’t need to worry about performances. In your case I’d start with logfiles and then change (or add more writers) if your requisites will change.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a few scripts on a site I recently started maintaining. I get
I have a few scripts that send out emails to my users, and for
I have a few IPython scripts which have redundant functionality. I would like to
I have a few sql scripts that I need to run via SQL*Plus. These
I have a few simple scripts that are intended to daisy chain together to
As part of my integration strategy, I have a few SQL scripts that run
I'm using a string builder to build some SQL Scripts. I have a few
I have a script which contacts a few sources and tell them the IP-address
I have a shell script which copies a few files to the current directory,
I have a ruby script that does a few perforce operations (through the scripting

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.