Heylo guys
i am writing an experimental AJAX page that checks the data of a txt file every 2 ms and if there is a change, post the change to the page
problem is that this is very inefficient bandwidth wise and computation-wise. Is there another way to do this? I have heard of websockets (not familiar though)
thx!
You can use COMET
http://en.wikipedia.org/wiki/Comet_%28programming%29
AJAX Push (Comet server) is exactly what you need. This is a very powerful tookit/engine: http://www.ape-project.org/
Instead of comparing the data, you could only compare the file size/last modified date on your server side script and return a 0/1 depending on if it didn't change or did.
Apart from that you'll have to tell us more about which language you're using on the server for us to be able to tell you what to do. You can use Long Polling or Comet, but it really depends on your server side language how good those would be. With PHP for example, I've found these to not be possible unless I installed stuff on the server, which in shared hosting for example is not possible.
Checking a text file 500 times per second is a bad idea, IMHO.
My suggestion is to have your server-side script check the modified date and "push" a notification to your AJAX listeners. Node.js and Faye would be good for this.
A good screencast on Node can be found here ($12):
http://peepcode.com/products/nodejs-i
That screencast also covers Faye (http://faye.jcoglan.com/node.html). Faye simplifies the whole Comet/polling process.
Related
I am working on a Project where I will try to compare different ways of creating a live ticker (news-ticker or sport-ticker whatever). I would also like to make benchmark tests, like how many connected users or how fast the data will come.
I have googled and found that usually tickers are build in PHP as the server and the client has an ajax call for every 30 seconds which will return the new Data.
Another way of doing this is with websockets (socket.io) and node.js!
With those two, I have worked and experimentet!
But are the other ways of building tickers?
Obviously you may replace any server-side language with php but are the other ways that the server sends data to the client?
Maybe with Flash ? or Ruby on Rails?
It would help if somebody could point out common ways of tickers and also modern ways or fast ways. I will then choose two of them and compare them!
I would really appreciate if someone knows good articles or links about this topic.
Thanks
I think it really depends on your requirements (update rate, etc.). I means if you update the news only a couple times a day, you will have some overhead if you maintain a Websocket open for nothing. All server technologies will do the same thing if you are requesting the data every 30 seconde or something like that, it is a typical ajax call. Did you considered using something that is already build like Jquery News Ticket
I was just wondering, How do comments appear instantly on Facebook? For example, when I'm on my profile and my friend comments something on my post, I can instantly see it. Is it AJAX? Or Queuing system? If I want to do the same thing, what do I do?
Thanks
I'm not exactly sure how facebook has implemented their system.
but it will either work with websockets, AJAX or a comet server.
If you want to have the same effect there are a lot of different techniques you could use,
but I would recommend looking into node.js and maybe even the now.js plugging, which allows for realtime updates via websockets. It even has support for older browsers, so if the browser does not support websockets, it will do a fall over to either a comet server implementation, AJAX or an iframe.
Basically websockets allow for better control over when data should be sent or received from and to the server since it constantly listening to the socket, so you only send data when required and same for receiving data as well, where with an AJAX approach you had to make a call every X seconds.
It's extremely easy to setup on a linux environment, and there's ample documentation to get you started.
It works with javascript and is build on the Google V8 engine, so if you've ever worked with OOP Javascript, you should be able to pick it up relatively easy.
LINKS:
http://nodejs.org/
http://nowjs.com/
You'll want to look into PHP sockets
Actually, its long polling according to this answer (which also explains how to verify or see if its changed since the answer):
How does Facebook fetch live updates
Rather a hard to nail down question, but basically I'm wondering what the best way (and not "what's your opinion" but "which will most adequately meet the requirement i shall set forth) is to open a stream connection from a client side webpage to a server such that either can send data to the other without polling? I'm thinking the term for this is HTTP binding vs. HTTP Polling. The context here is a chat application - i'd like a streamed connection so that the browser isn't constantly pushing requests out. The client end here is KnockoutJS and jQuery. I'd like to be able to have the data pushed back and forth be JSON (or at least manipulatable by jQuery and Knockout's toJSON). The server end - not quite sure what it is going to be, but i'll probably be running on a linux server, so anything compatible with that works fine.
If there's any more details i can provide, just let me know - i'm sure i left some obvious detail out. Also, i'm aware there's probably a duplicate question on this, so if your answer is as good as closing for a dupe and putting in a link, that's great.
Thanks!
I think what you're looking for is referred to as Comet. The basic idea is to keep HTTP requests open for longer periods of time so that the server can send data to the client as it comes in, rather than the client having to continually poll the server for new data. There are multiple ways to implement it. This Wikipedia article is a good start for more info.
This MIX 2011 video discusses the long polling technique (although the suggestion in the video is that web sockets will be a better solution with future browsers).
I am sure answer for this question will be very subjective, I simply want to know what the options are out there (for building a proxy to load external contents).
Typically I used cURL in php and pass a variable like proxy.url to fetch content. Then make an AJAX call with Javascript to populate the contents.
EDIT:
YQL (Yahoo Query language) seems a very promising solution to me, however, it has a daily usage limit which essentially prevents me from using it for large scale projects.
What other options do I have? I am open to any language, any platform, key criteria are: performance and scalability.
Please share your ideas, thoughts and experience on this topic.
Thanks,
you dont need a proxy server or something else.
Just create a cronjob to fetch the contents every 5 minutes (or whenever you want).
You just need to create a script that grabs the content from the web and saves it (to a file, a database, ...), which will be started by the cronjob.
If somebody requests your page, you just need to send the cached content out and do with it whatever you want to do.
I think scalability and performance will be no problem.
Depending on what you need to do with the content, you might consider Erlang. It's lightening fast, ridiculously reliable, and great for scaling.
Alright, I recently wrote a ajax push script which had php on the backend sleeping while waiting for someone to make an update. However, the sleeping processes took up a lot of cpu. Any ideas on how I can prevent this? I am guessing I will have to either find a program which can do the sleeping with threads or write my own in python or c++ which I am not very familiar with. I am using ajax push for a browser based game so people can play it in real time but I think if I get too many sleeping processes on the backend it would overload the server.
If I understand correctly, you want some kind of long-polling stuff -- you should search for the term "comet".
For instance, here are a couple of posts that might interest you :
Is there some way to PUSH data from web server to browser?
Online tutorials for implementing comets (server push)
Using comet with PHP?
Problem of choosing comet server
Comet & PHP: How to use Comet with a PHP Chat System ?
Still, one might say that PHP, because of its non-threaded model, I suppose, is not the best language/technology for that kind of stuff... And maybe you'll end up looking to another technology for that part of your site...
For instance, you can take a look at :
Choosing and deploying a comet server.
some links about reverse http:
reverse http 1
making-real-time-web-real-time
reverse http 2
rest-requires-asynchronous-notification
After much research last night, I found this as the answer for the server side.
Then write a php script for the client side.
Then have ajax call the client which calls the server.
Only problem is some of the extensions have to be manually installed.
http://php-mag.net/itr/online_artikel/psecom,id,484,nodeid,114.html