socket.io + php + is this a realistic solution at

2019-09-04 06:08发布

问题:

I have been reading about websockets and also about socket.io.

I understand websockets are not support but enough browsers yet to be realistically used.

socket.io has browser support but appears to need node.js. With my hosting solution I have some space on a shared server, very limited control over the server and have access to php but there is no node.js.

I have read that people can get socket.io to work with PHP.

Question: seeing I have very limited server access, not control over ports, command line etc is it realistic that I could get socket.io working with PHP or should I just stick with the AJAX calls (I'm currently using)?

Note: I've developed a chat solution and it appears it would be much more light weight if it was running with a socket solution.

Also - is there good security with Sockets.io?

thx

回答1:

Trying to make PHP talk to socket.io I suspect will be a big task.

Certainly it's not a great idea to run websockets via a pre-fork or threaded apache. Any event based server should be OK if you can handle the number of PHP processes. A better approach would be to write an event based server in php. Like this one



回答2:

i researched a few websocket server implementations. i read, that there is a way to use node.js in production. using apache many years, i also searched for a module to handle websockets within apache, but found only half-hearted stuff. nothing which seemed solid.

i stumbled upon yaws, which is a websocket capable server written in erlang, which has the advantages of beeing the right language for a highly parallel application such as the chat thing, and also because websockets should be well integrated within the main server.

now, i'm developing a php chat server, which uses a framework called ratchet. -> google for 'ratchet php'. they got a good tutorial.

i start it via the commandline, and although for you it should be possible to also start the ratchet server via a browser call, i would not recommend that.

so in your constrained hosting environment, i would stick to ajax.