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 6730567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:25:26+00:00 2026-05-26T10:25:26+00:00

I made a email queue in a database table(MySQL). Each row is an email

  • 0

I made a email queue in a database table(MySQL). Each row is an email message with recipient, sender, etc. And a script is automatically called every minute and it retrieves unsent messages and send them and set the ‘sent’ column of each message to true.

I need to ensure that each message is sent only once. But if the script runs long, another script might retrieve the messages and send them without knowing that they will be sent by another script.

Currently, I limit the number of rows to 50 at a time in order to keep the script running time short. But this doesn’t guarantee. I am sure there’s a better way.

Thanks.

Sam

  • 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-26T10:25:26+00:00Added an answer on May 26, 2026 at 10:25 am

    Building a reliable job queue is not easy. You definitively need to store more information than “sent/not sent”. The bare minimum I can think of is “Date taken” and “Date sent”. The delivery process should:

    1. Pick some available messages:

      START TRANSACTION;
      
      SELECT message_id
      FROM message
      WHERE date_taken IS NULL AND date_sent IS NULL
      ORDER BY message_id
      LIMIT 5
      FOR UPDATE;
      
    2. Tag them as processing:

      UPDATE message
      SET date_taken=NOW()
      WHERE message_id IN (101, 102, 103, 104, 105);
      
      COMMIT;
      
    3. Once done, tag them as sent:

      UPDATE message
      SET date_sent=NOW()
      WHERE message_id IN (101, 102, 103, 104, 105);
      

    You’d also need to release messages that have been taken for too long (since the process that took them probably crashed).

    It this is too much of a hassle, there’re some third-party mail queries like PEAR’s Mail_Queue.

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

Sidebar

Related Questions

I made a PHP script yesterday which send an email with a PDF as
I've made some function that generates an email template. Code it generates is pure
I have to made a page which will send Email to Newsletter subscribers. There
Made solution change: I am trying to display a html table of data.. In
I made a code that translate strings to match each word from the array
Im making a batch game, and made a email screen which looked like this
i've made a plist as a dictionary with dictionary entries, one for each ABRecord
I ran a script I made a couple of minutes ago and it still
I made a form with ajax email validation. My problem is that I need
I've made sure everything pertains to the column types in the database, but I

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.