0

I built a notification system that checks whether there are new notifications every 10 seconds using the setInverval javascript function, that sends ajax request and returns a json with the notifications.

I would like to hear alternative ways to do that, that doesn't have to be timed.

Is a while loop & a worker thread better? Since I'm working with PHP, how do I not overload the server with too many requests?

What are the security risks I am facing with my system, and with the system you'd like to suggest.

1 Answer 1

1

If you're not satisfied with your current mechanism, look into the cluster of various mechanisms collectively called "comet" and/or web sockets depending on the browser profiles you have to support (IE8 and 9 don't have web sockets, for instance). There are several libraries out there to help you with this, such as socket.io.

I don't think the security profile changes either way, but that would probably be a separate question in any case.

Sign up to request clarification or add additional context in comments.

6 Comments

Does php support sockets?
@JacobCohen: :-) A quick search for "php websocket" turned up Ratchet, phpwebsocket, and this SO question and its answers: How to create websockets server in PHP.
Unfortunately, it seems like both are working on the same idea. Client sends a request to the Server, and gets an answer and decides what to do with it. I need the client to keep listening to the server, and when the server sends a message, the client will do what it wants with it. Still reading about socket.io, it might be doing what I need.
@JacobCohen: What makes you think that? From the Ratchet "Process Flow" page: "...once the webpage has been loaded a WebSocket connection is made back to your Ratchet application, where if everything goes correctly, a connection remains open where either the server or client can send data to the other one at any given time."
@JacobCohen: Re socket.io, most of what you'll find is based on a NodeJS backend, but if you search around, there are PHP projects for socketio backends in PHP. I don't know how good they are, never having had to use one.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.