My colleague and I developed a chat in CakePHP 1.2 (the system is somewhat old) using Ajax. But the only problem is that it needs to be making requests to the database at all times, with a defined interval, in search of new messages, more or less like a boring guy asking "has a message? Is there a message? Is there a message?", and this can overload the server if it is heavily used, and this method is not a good practice. The interval, by the way, is quite short, for a better user experience.
Anyway, I would like some functional alternative, simple and efficient. Something that, when sending a message, the bank already tells the other user "you have a message", the opposite of what happens.
I researched a lot of sockets, but I did not know how to implement them in the code. I also thought about doing in AngularJS, but also to no avail. The chat works perfectly, but it has such a catch.
I'd rather keep secrets about the system.
If anyone knows anything, I'll be grateful.