notify users when changed database

I don’t want Ajax request to be sent every 2 seconds. Is there a way to send me a notification only if the database changes in a certain meta?

You can’t watch the database for changes like this. The most you could do is add filters on post meta changes on the PHP side to trigger an event.

The problem is that you would then need to send that data to the browser, and the only way to do that with PHP is polling. Polling is unavoidable if you are going to use only PHP.

To get a continuous connection that allows you to push the event to the user unprompted, you need a websocket, and that is not something you can implement in PHP with WordPress. You will need to explore non-PHP alternatives to implement your chat server/livechat.

Of note, uses websockets for live comment updating and notification updates, however in order to do this, their PHP sends a ping to a separate service that runs in Node.js which can run websockets. Note that all of the options require additional hosting requirements that go beyond the standard PHP+MySQL of a WordPress site.

Livechat and chatrooms have their own storage and coding requirements that don’t fit so well with WordPress tables such as post meta.