4

I'm running a nodejs / socket.io (v 0.7) server to push data to web clients. That works greatly.

To extend the application, I need to trigger / influence socket.io over php. I know a solution that works with cURL over http with the nodejs http server.

One possible solution is to run the socket.io server and the nodejs http server in one an the same app.js. The clients connect and communicate with socket.io, and the only allowed connection to the "seperate" http server (listening on another port than socket.io, of course) is from 127.0.0.1 respectively from the php server over cURL.

Because the both servers are in the same scope, the http server can trigger events on the socket.io server.

My Question: doest that make any sense? Is there a cleaner solution to trigger events on socket.io from PHP?

3 Answers 3

1

I think that's a reasonable and straightforward way to go; it seems like caution would be advised for dealing with order of execution, but that's probably just my uncertainty with node showing.

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

Comments

1

I am writing a solution which I think looks a lot like pusher API. It utilizes room(channel) concept. From a route via express I can curl(via PHP) to send messages to room(channel).

io.sockets.in('your room').json.send('your json');

I'd like to open-source that project in the future(hopefully within a week), but hopefully you get the picture.

5 Comments

Hi Alfred, don't know if that's what im lookin for. Anyway, if you have something great and opensource, don't forget to post the link here when you're done!
Have you ever published your solution? I'm very interested in this.
@EsTeGe I regressed :$, but I would like to continue work on it.
Maybe you can create a github repo for it so that the community can help you with it.
I was thinking about that :). I will try and post something on github really soon.
0

socket.io with version greater than 1.3.3 (may be older),you can trigger a emit event as below

//send broadcast message to all connecting clients
io.emit([message event],[your message body obj or str]);

// send to specific user
io.to([your room]).emit([message event], [your message body obj or str]);

Comments

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.