0

enter image description here
**My Question ** while chatting on Facebook , when u receive a message from someone, you get a notification showing number of new messages with red background. so my question is how we can do so that we recieve a notification when database is changed from another computer. I done it with the following codes and it work well but it seem harmful for processor as it run mysql query each second.

the following jquery code

$(document).ready(
            function() {
                setInterval(function() {
                    $.ajax({
                        url: 'incs/check_new_msg.php' ,
                        cache: false,
                        success: function(data)
                        {
                            $('#orders').html(data);
                        },

                    });
                }, 1000);
            });

in check__new_msg.php i use query select count(id) from inbox where status = '1' then i echo its result

Aftab Ahmad
  • 354
  • 1
  • 2
  • 16

1 Answers1

1

You are looking for concept of reverse ajax.

Here is one answer given to implement it: Reverse Ajax implementation using php

Community
  • 1
  • 1
Apul Gupta
  • 3,044
  • 3
  • 22
  • 30
  • thanks sir. let me check it – Aftab Ahmad May 15 '15 at 14:48
  • There are several ways of going about this, as this other thread details. Websockets is a popular one (keeps an open connection between the browser and the server) but must be configured on the server. – Bryan Zwicker May 15 '15 at 14:50
  • sir i already done it with ajax request and js timeinterval , but it heatup processor by running query each second – Aftab Ahmad May 15 '15 at 14:53
  • If I understand correctly, OP wants to make normal client --> server ajax requests ... and not the reverse. – Yogi May 15 '15 at 15:39