If you have ever been to a sms messaging site, you probably have seen that users can decide they want to schedule the sending of their sms message at a later time.
So a user logs on to the site (a real life example is at http://www.smslive247.com or http://routesms.com), composes the sms and clicks on "send message at a later time" radiobox. This gives users a datetime field that you can then pick what date and time you want the message to be dispatched (as well as ability to change the timezone).
Basically, users can schedule the sending of sms.
I'm also designing a similar site and wondering if anyone can tell me how this is done.
Thanks.
Use a message queue, for example in a database, that gets read by a separate process (a service, or cron job for example) that processes the records and sends the message.
One approach is to store the message and write a service to send queued messages. You can store the messages in a database.
One approach is to use a database.
Create a table with a column that contains the datetime the message should be sent, and another column with the message.
From a background thread (or even another process, such as a Windows Service or a SQL Agent task), wake up every once in a while, read the top row in the table, and see if it's time to execute it. Something like:
CREATE TABLE MyQueue (
TimeToExec DATETIME NOT NULL,
Message NVARCHAR(MAX) NOT NULL
)
INSERT INTO MyQueue VALUES(GETDATE(), N'message')
;WITH MYCTE AS (
SELECT TOP 1 Message
FROM MyQueue
WITH (ROWLOCK, READPAST)
WHERE TimeToExec <= GETDATE()
ORDER BY TimeToExec
) DELETE FROM MYCTE
OUTPUT DELETED.Message
Related
I have a Mysql database which contains the status of many orders and where they are located. Im looking for a way to notify my customer on the update of the status of their order.
Basically everytime the column "status" would be changed ( could be done with a trigger of some sort ) , trigger an event that would somehow be able to call an external script (preferably PHP) to either text or email my customer that their order has been updated and that the status is now X, if completed , tell them to come pick it up.
I've read around that triggering script from a mysql trigger is extremely bad pratice but I'm wondering if there are other options to do something like this.
Any suggestions?
Hi everyone Im working on a symfony2 project,and my next step is to create a simple notification system,
when someone add insert a row in an entity, the others must be notified in the moment,
I wonder if I create a bloc of jquery code that get the date of the last created element and then do the rest work (show a notification ) I dont think is a good idea, or if there is a nice and a simple method to follow to create a notification system,
plz any idea could be helpful.
Thanks in advance!!!!
You shoul implement something like this:
Client send an ajax request with timestamp of last modification (first time sends 0)
Server compares timestamp of client to timestamp, to retrieve all messages with bigger timestamp than the one sent by user
If there are newer messages, return them immediately to the client, with the timestamp of the latest one On other hand, if there are no new messages, enter into a 2 minutes busy-wait loop, checking every 1-3 seconds (randomly) whether there are new messages.
When client receive servers answer, browser updates view and immediately sends a new ajax request.
I want to build a simple message system between my users of my website. For that i constructed table for messages as below:
tbl_messages
-pk id int
-fk sender_id int
-fk receiver_id int
-is_read boolean
-send_date datetime
When a user has my site opened in the browser and some other user sends him message, i want to send a notification message to the receiver user (something like 1 new message or (3)Messages) while the page of receiver is opened.
Eg: facebook notification, stackoverflow notification comes when new comment arrives
I performed such action by making a javascript function to be called every 2 min. This function makes an ajax request to output the notification. I wonder is this the correct and effective way to do because i have to perform the sql query every 2 min and if there are lots of records in my table, such action will create more load on database.
What other solutions can I perform instead of this?
If you correctly indexed your database and designed your program, it shouldn't be a problem.
You won't be able to design a notification system as responsive as Facebook and other, since it's almost impossible to create push systems with PHP.
If you have a dedicated/virtualized server (and not shared hosting), look into things such as NodeJS.
I have a flash application. I'm trying to send users text messages via php after they did certain things on the flash.
For example,
Text user 1 hour after they did
thing#1.
Text user 10 minutes after they did
thing#2.
Text user 1 day after they did
thing#3.
....
I'm thinking of setting up a table for the list of things that will trigger the text. Then have a cron job set up to check the timestamps of each user finishing those things.
Is there a better way out there for doing this?
That sounds like the approach I would take. Whenever you have an action that takes place at a different time than the web request, you need to "queue" that action up to be completed later. Then you need a script that runs (however often you want) that checks the queue (i.e. DB table) and processes the items in the queue.
You're on the right track.
We have a back end application to manage messages from our clients. We have 4 customer care executives and we want to prevent the situation where the same message can't be opened by two different members, so we would like to do following...
Suppose user1 opened message id 15 and after that user2 opens same message, so we would like to give a alert that 'This message is already opened by user1'. How do we do it?
Create a different table in your database.
When a user opens a message, update the table to show which message has been opened and by which user.
When another user tries to open it, crosscheck the table to see if there is a row for that message. You can then do the appropriate action such as open or warn the user.
You can delete the rows after a given timeout period to allow others to open.
Schema eg
User_id msg_id time_opened
Unfortunately, you can't use sessions since the sesssion is user specific. However, you can employ flatfiles.
To delete the rows, employ a method such as
$timeout_time_in_seconds = 30;
$time = time() - $timeout_time_in_seconds;
$Query= "delete from table where time_opened
Note that depending on the time field, which can be an int, datetime or timestring, additional date formating of the $time variable may be required. However, int will be most convenient due to ease in comparison and subtraction and no formatting.
I'm mobile so pardon any errors. Also that's why I didn't comment but had to edit. Js issues.
What happens is, when the first user clicks, a quick check and update of the database is made.
When the second user tries, the script will detect the first user has already opened by checking the database.
You can count on this to work if the traffic load is low and the number of users trying to access is not too great. And also counting on the fact that the read and insert queries occur in a short time which as you can Guess is faster then two users clicking at the same time. Unless you have another issue, this should work
Simpliest way would be to implement as pessimistic locking at the DB level
http://www.blackwasp.co.uk/PessimisticLocking.aspx
Whatever language you are using should let you check the DB to see if a row is locked or not and send a message on the screen.
You can additionally setup your application with long polling to notify users when the request resource has become available. http://en.wikipedia.org/wiki/Push_technology