HTML5 - WebSocket in shared hosting

I had a small chat application (which almost worked) that uses PHP, jQuery and MySQL. The volume of users is very small (only my friends use it). For this, I used a long survey method.

And now, I'm thinking of using HTML5 Websockets for this, because it is much more efficient. And also most of my friends use Google Chrome (which already supports HTML5). I looked through some tutorials about HTML5 websites. And I downloaded phpWebSocket from github. I went through the code. But the readme file says that a PHP page that listens for incoming connections should start using "PHP -q" from the command line. So, I was looking for what this q flag would do. And I found that it runs the page in silent mode. So, when I run it in silent mode, what happened? Will it be endless? Will this current process affect system resources?

This PHP page should work all the time. Then only connections can be accepted. Is not it?

I have a hosting package with HostGator. And they also let you do cron jobs. And my real chat application (which uses the long polling method) inserts all the messages into the database. When the user polls, he will search for any new messages from the database and then display them (if any).

So, I'm a little stuck here. :(

+5
source share
3 answers

It should be run from the command line, because, as you suspected, it should work endlessly. It binds to a socket on the server and listens for incoming connections. It cannot be reliably launched from the browser.

The -q option indicates that it does not display any browser headers, such as X-Powered-By: PHPorContent-Type: text/html

, PHP, . . , , . select, .

, , , , , , , .

, URL- WebSocket ws://localhost:12345/websocket/server.php. -, WebSockets, - phpWebSocket, , 80.

, .

+5

Perhaps you can use CronJob to run the command line,

-3
source

All Articles