1.) How can I notifiy a client about an event like "you just received a message" in PHP and jquery? (maybe in the look and feel of stackoverflow)
I don't send the message itself because it is stored in a database.
Read more to understand the background of my question...
The environment:
I've build a very simple messaging system. For the implementation I used PHP and jQuery. Here is what you can do with this little messaging system:
Client:
- Type and send a message to desired contact.
- Click on a contact to read whole conversation (from database).
Server:
- Receive a message and store it in a database
- MISSING: Notify client when a message is stored for him
This is all you need to know I guess.
As a client I need to reload the page manually to get the message content
Today I've read a lot about websockets or the possibility to send a notification from server to client via SSE and ajax.
Thoughts about Websockets:
There is a lot of work to do before I can start sending and receiving messages. I don't need a real time chat yet. Its just a messaging system that looks like a chat. I need a chathistory too, not a chat only!
Thoughts about SSE and Ajax:
As described in this Answer: Performance of AJAX vs Websocket REST over HTTP 2.0?
I'm Afraid that I have a lot of work with this: "Unlike Websockets, both SSE and Http+AJAX are stateless, so you need to go through authentication for every new message cycle, decoding the Http/2 headers, encoding the Http/2 headers and using all the resources related to a fresh request..."
Final question
Should I stop here and do it with nodejs and some nice npm packages instead of finish the PHP solution?