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

  • SEARCH
  • Home
  • 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 7538513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:08:23+00:00 2026-05-30T07:08:23+00:00

A very common need for an application is to run a script every X

  • 0

A very common need for an application is to run a script every X minutes/hours. Basically its nothing complicated, just some PHP code and a crontab entry.

Although I’ve written quite a few of those cronjobs in the past years I still haven’t seen any best practices, at least not that much. As with every “background processing” so many things can go wrong especially in a production settings.

Among them:

  • an error occured during execution of the cron and the script died processing half of the data
  • the cronjob was accidently started twice by another process/by user error/whatever
  • the cronjob took way longer then expected and the script is called again although its not done processing data
  • etc.

What are some best pratices for writing rock-solid, robust cronjob scripts? Writing a lock file asserting that only one instance runs, extensive logging and monitoring in oder to prevent sending ten thousands of duplicate emails? What are your ideas?

  • 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-30T07:08:24+00:00Added an answer on May 30, 2026 at 7:08 am

    Personally, the way I handle errors is to simply send STDERR to a log file, and then periodically check that file. An easy way to do that, is to append 2>/pathtolog to the crontab entry.

    As far as having duplicates of the same program running, I prefer to have the script attempt to lock something (a file or a local network port). If it fails to obtain that lock, the script does not run. This way, if an existing script is currently running, a new one cannot obtain the identical lock.

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

Sidebar

Related Questions

I have a very common situation. I have a file, and I need to
It is very common to create Dependency Injection container for the ASP.NET application so
I would like to include very common feature in my web application. I would
I need to store files into the common desktop on Windows. The application is
I have very basic QT application (just create to explain my problem). So here
The very common beginner mistake is when you try to use a class property
I have a very common situation here. And for years I haven't found if
This is a very common scenario: displaying images in a ListView which have to
This seems like a very simple and a very common problem. The simplest example
In Java IoC / DI is a very common practice which is extensively used

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.