简体   繁体   中英

implementing chat system php, obj-c, and mysql

I am a newbie API developer using PHP and we have a new client who wants to include chat system in the app that he wants to develop. I already created the native way by creating a table in mysql with sender, receiver, message, time_stamp field and I already created a set and get API call for Messages. But the client seems not satisfied because by default it is not real time. My front-end developer just call the GetMessage() on an X seconds.

What I want is to make it real time just like what Facebook or Skype app do. When new messages was inserted in the database the server will just poke the app that there is a new message via push notification I think? So in that case the app will not get messages on every X seconds. So basically once I hit the send button, on the other side, the receiver will just see it synchronously.

Take a look at something called triggers. They are activated in mysql when insert, update or delete-event occurs. An important thing though is that SQL has to used for triggers to be executed. The triggers would not execute from external api's.

You might for an example set some value in a table that tells that a new message has arrived for a certain user when a new insert is made into the db.

Starting points:

http://dev.mysql.com/doc/refman/5.0/en/triggers.html

http://dev.mysql.com/doc/refman/5.0/en/faqs-triggers.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM