this post was submitted on
6 points (80% like it)
8 up votes 2 down votes
all 17 comments

[–]vduquette 2 points3 points ago

sorry, this has been archived and can no longer be voted on

[–]zushiba[!] 1 point2 points ago

sorry, this has been archived and can no longer be voted on

http://nodejs.org/

Node.js is a server-side JavaScript environment that uses an asynchronous event-driven model. This allows Node.js to get excellent performance based on the architectures of many Internet applications.

[–]nrogers64[S] 0 points1 point ago

sorry, this has been archived and can no longer be voted on

Thanks for the suggestion. Could you please be a little more specific? I'm a Apache, MySQL/PostgreSQL, (Cake)PHP guy. That's all I've ever known.

Are you saying I should create a server with Node that does nothing but handle WebSocket stuff or do the whole backend logic in Node as well or what? What would you do in this scenario? What web server and programming language would you use? I would very much appreciate the help. Thanks!

[–]zushiba[!] 0 points1 point ago

sorry, this has been archived and can no longer be voted on

I wish I could give you more information but I've only dabbled in Node.js. I'm a LAMP guy myself but from what I did gather from playing with Node.js you'd probably have to do most of it in Node.js. I'm not sure how you plan on pushing notifications but you might be able to get away with an iFrame.

My project was a simple chatbox that'd be integratable via an iFrame. I didn't get very far but the capabilities of Node.js did impress me, I only quit because after some time I figured it was faster to just go with a more simple ajax implementation.

Honestly, while you could accomplish what you're looking to do with Node.js, if you're more familiar with PHP than Java you'd probably get further, faster with long polling.

Node.js's can achieve the immediate notification you're looking for. If your not looking to do anything amazingly complex it's not a bad option. I do suggest giving it a try just for fun though it is a very neat thing to play with.

[–]nrogers64[S] 0 points1 point ago

OK, well thanks for the advice! I really appreciate your time.

[–]nemeth88 0 points1 point ago

sorry, this has been archived and can no longer be voted on

You probably want to use an event-based webserver (JavaScript/Node, Ruby/EventMachine, Python/Twisted) rather than a request-based server (PHP/Apache) - PHP isn't designed to work as a long-running server process, but rather is supposed to run short 1-2 second scripts that then get cleaned up when the request ends.

As an example, check out http://socket.io/ for Node.

[–]WDKevin 0 points1 point ago

sorry, this has been archived and can no longer be voted on

The server wouldn't matter a whole lot. You're going to want to use AJAX to push notifications to the user, PHP is a server side language and renders all it's code before the website is returned to the user. jQuery will probably be a friend of yours in this project as well.

[–]mikedoesweb 5 points6 points ago

sorry, this has been archived and can no longer be voted on

Um....

Ajax is not a magic bullet, and certainly will not push notifications to a user. Ajax is just a method of using javascript, which runs on the client side. What he could do with Ajax is set a timer and ask the server every x seconds if there is an update. However -- with a large number of users this would place a huge strain on the server.

OP, what you actually need to look at to truly do this is Comet, a

web application model in which a long-held HTTP request allows a web server to push data to a browser, without the browser explicitly requesting it.

or, in HTML 5, Websockets

[–]nrogers64[S] 0 points1 point ago

sorry, this has been archived and can no longer be voted on

Thanks for the advice. Which web server and language would you use if it was your project?

[–]cmwelsh 1 point2 points ago

sorry, this has been archived and can no longer be voted on

You'll want to use more than one web server. Node.js is nice for long-polling/WebSockets but something like PHP/Python/Ruby might be friendlier for designing other functions of the site.

You are looking at a pretty serious undertaking with multiple kinds of web servers to get this right. I would use WebSockets with AJAX long-polling as a fallback. http://en.wikipedia.org/wiki/WebSocket

[–]Kaz3 0 points1 point ago

sorry, this has been archived and can no longer be voted on

Isn't that what Facebook does though, use AJAX requests to get friend updates? Every 5-10 seconds it sends a new request, which I assume gets updates.

I'm considering doing something similar as the OP for a work project and I've looked into Node.js and sockets, but neither of them seem mature enough.

[–]WDKevin -1 points0 points ago

sorry, this has been archived and can no longer be voted on

[–]cheald 2 points3 points ago*

sorry, this has been archived and can no longer be voted on

Long polling is not "push". It's polling. You can't truly push anything with AJAX. The server can elect to just sit on a request until it has data to serve, which is what happens there.

If you want actual push functionality, you have to use websockets. You also need a specialized server that can handle websocket connections.

[–]jij 2 points3 points ago

sorry, this has been archived and can no longer be voted on

And with 1000 uses (assuming all at once) you better have apache set up correctly.

[–]nrogers64[S] 0 points1 point ago

sorry, this has been archived and can no longer be voted on

What settings would you recommend?

[–]MiHeath 1 point2 points ago

sorry, this has been archived and can no longer be voted on

You can do comet with PHP/ajax as documented @ http://www.zeitoun.net/articles/comet_and_php/start#comet_with_classic_ajax_litte_chat_demo ... I'm not sure 1000 users would be a straing simply using ajax though, especially if you limit how often the call is made (can probably be done every 30 seconds- minute) or even cache the contents of the php file being cached for a certain amount of time to reduce server load. Yes 1000 requests/second is a bit much, so try to avoid that scenario, but combining a few of the options could work as well.

[–]MiHeath 1 point2 points ago

sorry, this has been archived and can no longer be voted on

of note though, 1000 users on Comet without a server such as nginx could be restrictive, as it would require 1 thread per connect. This actually seems to be MUCH less feasible than the AJAX solution for your specific request, unless of course you do have a server able to handle 1000 asynchronous php requests.

Other languages/platforms handle this a little bit better, but it is still one of the major drawbacks of Comet.