Websockets on shared hosting?, push communication without command line?

Hello,

I’ve just very briefly glanced at a few ‘how to do websockets with javascript and php’ pages. They all seem to involve opening a command line on the php server side.

How does that play with the typical hosted php situation?

Further to that question, what I’d like to make is a situation which allows me to open a window/page off of my server. Leave open in browser. Then when another particular php page is accessed, by someone else, on another computer, for that fact to be instantly communicated to my window. Possibly/hopefully no command line use?

So that situation wouldn’t require a constant running php script. But it would require a php script to communicate outwards to a different user than the one who’s requested the page.

Possible? How? Any pointers/suggestions much appreciated. Thanks.

This looks like it’s an answer to what I’m asking: http://stackoverflow.com/questions/14888990/setting-up-websockets-without-command-line

[quote]Assuming your shared hosting provider supports crontab and cron jobs (most of them do), add the following job to the crontab:

@reboot nohup php /path/to/server.php 2>&1 >/dev/null &
Additionally, you need to start it now, so simply create the following PHP file and access it once, in your browser:

<?php shell_exec('nohup php /path/to/server.php 2>&1 > /dev/null &');?>

That should do the trick. Hopefully your shared hosting provider allows execve() calls to be made. Good luck![/quote]

Not sure if it works or will work for me / my server setup but appears to be a good possibility.

Do you have access to the source of the php code that the other person is accessing, that is, can you insert code into that? I’m imagining some kind of logging where the other php page records the fact that it has been opened, and your open page frequently checks the repository and reports any new records. So it wouldn’t actually be pushing data out, just looking like it is.

Yes, it’s my code. Same server. That’s not the problem bit.

It’s that constant polling, javascript code in web browser constantly repeatedly asking server, “anything to report?” that I want to avoid. I’m looking for it to be really quick, so I’d have to poll every second or two. Much prefer to be able to sit there and wait for server to say without being asked. But failing all else, that would be the way I suppose.

OK, I’m fairly out of touch with what’s possible these days, I’m sure someone else will be along with suggestions if there are some. Does Facebook just poll the server repeatedly? I get notification if someone responds to a post while I’m still on the site.

As a purely sockets thing and leaving out the browser aspect of it, you’re basically wanting to have your application run as a server which will monitor a port, your other page would then post data to that port when the other user runs the page. I could see how to do it as a standalone application, but not as something in a browser. Maybe the PHP area isn’t the right place for this, fine for the mods to the other page but I can’t see how it would work as the server task.

I don’t know, good question. If it does that must mean the cost in terms of browser processing and server processing and bandwidth is minimal enough. The whole point of web sockets is to do what I’m asking and they are supported by a lot of browsers I believe, their support isn’t so rare, so my guess would be that FB uses sockets. ….

Rather than guess I thought I’d search, and found:

http://stackoverflow.com/questions/1086380/how-does-facebook-gmail-send-the-real-time-notification

It’s brilliant. I’ve only read the first few sentences.

I’ll try that. No web sockets.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.