How to send a PHP request to another user through Ajax?
For example, if user
As Barmar said, WebSockets is the de facto standard to handle continuous polling scenarios.
Should you opt to go with continuously polling AJAX, an expected design would be along these lines:
Aposts data to a PHP program on the server.
- The PHP program saves the user's action into a 'cache' table in a database.
B's client eventually makes an AJAX request to the server.
- Any items in the 'cache' table that contain that user's user ID (
$_SESSION['user_id']or something to that effect) will be returned to user
B's client alerts them that a message was received.
Keep in mind that even if you only poll every 30 seconds, with enough users you could end up DDoS-ing your own server while polling for messages.
WebSocket RFC - https://tools.ietf.org/html/rfc6455
WebSocket Basics - http://www.html5rocks.com/en/tutorials/websockets/basics/