javascript - How to use Comet and Push technique using AJAX and PHP -
i calling ajax after each 5 seconds update info of current logged-in user database table in php.
but creates heavy load on website, , website down after time when there multiple users logged-in on website.
is there way use other techniques comet or push improve script?
here code using:
javascript code:
jquery(document).ready(function ($) { update_data(); function update_data() { $.ajax({ type: "post", url: "$url", data: {update_current_time:1}, success: function(response){ settimeout(update_data, 5000); }, error: function(){ settimeout(update_data, 5000); } }); } });
php code:
if(isset($_post['update_current_time'])) { $query = "update users set user_timer=now() user_id=".$_session['id']; $db->execute(); echo 'success'; die; }
to use push or comet need setup "webserver" listen port. cannot solved using pure php needs listener setup (unless create on listening server using php).
to stay @ php can check out ratchet.
another common way go node.js server parrallel webserver.
Comments
Post a Comment