Reverse Ajax implementation using php

I am looking to implement inverse ajax in my application that uses PHP and jquery. I worked a bit on this and found XAJA, but it seems like a paid application. Is an open source application available for it, or has someone implemented it?

Some pointers or tips will be very helpful.

Thanks in advance.

+6
php reverse-ajax
source share
4 answers

I know two types of reverse AJAX:
1- Poll
2- Press

I think the survey is easier to implement, you just want your javascript to make a regular request to the server every time period, and when the server has some data for it, it will respond. It's like a ping, and some call it a heartbeat, but this is a very obvious solution to this problem. However, it can easily overload the server.

EDIT Simple Poll Example Code:
Server:

<?php //pong.php php isn't my main thing but tried my best! $obj = new WhatsNew(); $out = ""; if ($obj->getGotNew()){ $types = new array(); foreach ($obj->newStuff() as $type) { $new = array('type' => $type); $types[] = $new; } $out = json_encode($types); } else{ $out = json_encode(array('nothingNew' => true)); } 


Client-Side:

 function ping(){ $.ajax( { url : "pong.php", success : function (data){ data = JSON.parse(data), if (data['nothingNew']) return; for(var i in data){ var type = data[i]['type']; if (type && incomingDataHandlers[type]){ incomingDataHandlers[type](); } } }); } incomingDataHandlers = { comments: function () { $.ajax({ url: "getComments.php", method: "GET", data: getNewCommentRequsetData() // pass data to the server; success : function (data){ //do something with your new comments } }); }, message: function (){ $.ajax({ url: "getMessages.php", method: "GET", data: getNewMessageRequestData() // pass data to the server; success : function (data){ //do something with your new messages } }); } } $(docment).ready(function () { setInterval(ping, 1000); }) 
+1
source share

You are looking for what they call a "long poll" - I did a "long php poll" and I got this thread on a stack overflow:

How to implement the basic "Long Polling"?

+1
source share

you can create web sites in combination with flash websites because almost all browsers have flash memory (on average about 96%? => http://www.statowl.com/flash.php ) = > https://github.com/gimite/web-socket-js . You can use this with http://code.google.com/p/phpwebsocket/ . However, I am wondering if the performance will be good. If possible, I would use node.js to reverse ajax. http://socket.io is a really cool project for this!

0
source share

Did you mark APE ?

Its real-time streaming technology for streaming in one low-volume ajax connection. The concept is useful, you can copy the same using your server implementation

0
source share

All Articles