Friends have such a question, I need to play a sound when a new message appears, my pkhp script successfully sends jason ajax to an array with the result of the sample, and then I in the jaquery cycle output messages if I push a function in the cycle that plays the sound, it will naturally be played a hundred times once and then when a new message arrived. The question itself is how to track whether something has changed in the database or to count divas, and then check if their number has increased? Sampling is done by means of the mayesquelai aop approach. Sorry that everything is in Russian with weave

    2 answers 2

    You have messages, probably have a unique numeric identifier. When sending a request for the presence of recent messages, I would send it, check on the server whether messages with an ID greater than the transmitted one appeared, and if they did, send a new message presence flag in the response, well, already analyzing this flag lost or not playing music.

      Yes, about the way it is, as aldem67 writes, the script checks every 30 seconds for the current identifier in the database, if it is greater than the one that it has in the browser, then the data can be considered modified. The second option, Web Sockets, socket.io , the server notifies when the service changes, which in turn notifies the browser that the data has changed. This is how Vk wall and messagi work. About PCP and web sockets for habr.

      • And what if id is practically random? not id = {1,2,3,4,5 ...}, but approximately like the number of the movie on the tube - id = {x35fjvh228, zj937vksd, ...}? - aryndin