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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:20:46+00:00 2026-05-24T18:20:46+00:00

Let’s say i was writing an aplication where’d i’d need to get notifications in

  • 0

Let’s say i was writing an aplication where’d i’d need to get notifications in real time from a server, and let’s say those notifications are stored on a mysql database.
For me to get them i’d have to keep polling the mysql server (keep repeating the same select
query till i actually get results) but i figure that is very unefficient way of doing it since most of the time the select would turn up empty . If i do it often it’s unreasonable strain on the server if i do it rarely the notifications would come in very late.
So i was wondering if there is a way for say a mysql query to block until a result matching a condition becomes available.

list = query ("SELECT * FROM `notifications` WHERE `unread`=1") ;

instead of returning an empty list if there is no unread notifications , it would instead wait till there actually are unread notifications to return

  • 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-24T18:20:47+00:00Added an answer on May 24, 2026 at 6:20 pm

    I recommend using the producer consumer pattern, implemented with a new table as the “work queue”. There is no need for a stored procedure, because the trigger is so simple.

    1. A trigger would populate the work queue
    2. Code would poll the work queue table. Because the table would be very small, the query would be fast and low-load.
    3. Code would do whatever you need and delete rows from the table when finished – keeping it as small as possible

    Create a table with the id of the notification to be processed and a “processing status” column, for example:

    create table work_queue (
        id int not null auto_increment,
        notification_id int references notifications,
        status enum ('ready', 'processing', 'failed')
    );
    

    Create a simple trigger that populates a the work queue table:

    delimiter $
    create trigger producer after insert on notifications
    for each row begin 
        insert into work_queue (notification_id, status) 
        select new.id, 'ready'
        where new.unread;
    end; $
    delimiter ;
    

    Your code would have the pseudo code:

    1. select * from work_queue where status = 'ready' order by id limit 1
    2. update work_queue set status = 'processing' where id = <row.id>
    3. Do what you need to notifications where id = <row.notification_id>
    4. either delete from work_queue where id = <row.id> or update work_queue set status = 'failed' where id = <row.id> (you’ll have to figure out what to do with failed items)
    5. Sleep 1 second (this pause needs to be about the same as the peak arrival rate of notifications – you’ll need to tune this to balance between work_queue size and server load)
    6. goto 1.

    If you have a single process polling, there is no need for locking worries. If you have multiple processes polling, you’ll need to handle race conditions.

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

Sidebar

Related Questions

Let's say I can call a method like this: core::get() . What is the
Let's say, if I need to assign an id to element with first name,
Let's say I have a queue called notifications and I post 1000 messages to
Let me try to explain what I need. I have a server that is
Let's say I'm writing a PHP (>= 5.0) class that's meant to be a
Let's say I have an Instant Messenger server using SignalR. I want to broadcast
Let's say I have a javascript array with a bunch of elements (anywhere from
Let's say I'm writing a Windows Forms (.NET Framework 3.5) application which shows the
Let's say I want to write an FTP client from scratch. In the command
Let's say I have such MYSQL table for logins: id---name---location---login_date ---------------------------------- 1----mike----usa-----21.08.2012 2----tony----uk------22.08.2012 3----tony----uk------23.08.2012

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.