-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sometimes works, sometimes doesn't #14
Comments
I just wanted to say that I can sort of workaround this for my purposes - I'd love to see a solution, but I can at least see that the php client has connected and fire an event to my clients that basically just says "update." It seems to work okay, but I'd like to hear if you have a solution. Server:
Client
|
For anyone looking for a similar solution, I ended up going with this. https://stackoverflow.com/a/49864533/1274820 I was looking for a really simple way to get PHP to send a socket.io message to clients. This doesn't require any additional PHP libraries - it just uses sockets. Instead of trying to connect to the websocket interface like so many other solutions, just connect to the node.js server and use Then, Detect a connection from your PHP server in Node.js like this:
Here's the incredibly simple php code - I wrapped it in a function - you may come up with something better. Note that
You can use it like this:
You can also send arrays which are converted to json and passed along to clients.
This is a useful way to "trust" that your clients are getting legitimate messages from the server. You can also have PHP pass along database updates without having hundreds of clients query the database. I wish I'd found this sooner - hope this helps! 😉 |
Hi, Nice writeup. The power of socket.io is in maintaining connections open, and updating data without performing requests. |
Correct me if I'm wrong, but can't you just leave the socket open and send data as needed? |
I solved this problem this way: |
I found better solution. The previous version overloads the server when large online. socket.on('ACTION', function (data) { // on event from php-library
io.to(data.room).emit('ACTION', data); // sending data
socket.disconnect(true); // disable connection due to php-library bug
}); |
Sure, but php by definition creates an "instance" per request. This is great for REST api requests, but if you want to make a permanent solution, there are better alternatives. In my case I solved this by using redis to pass data to the node instance, and doing a proxy for the /socket.io/ location in nginx. |
I had the same problem as TyraelElDruin with this class. Sometimes my message arrived, sometimes it did not. I solved it by placing a sleep(1) after the first fwrite(). |
I'm hoping to use this on something I'm working on as a simple way to pass notifications to clients.
The issue I'm running into is that sometimes this works and sometimes it doesn't - there doesn't seem to be much rhyme or reason to it.
Sometimes it will instantly connect/disconnect without sending the message along - other times, it succeeds.
Have you tried using this to send multiple requests in succession?
The text was updated successfully, but these errors were encountered: