究竟需要设置PHP Websocket服务器吗? [英] What exactly entails setting up a PHP Websocket Server?

查看:300
本文介绍了究竟需要设置PHP Websocket服务器吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在正在使用Web套接字,并且已经成功地使用了在线websockets Pusher(不喜欢它)和Scribble(令人惊叹,但是停机时间太频繁了,因为它只是一个人在运行).

I'm getting into Web Sockets now and have been successfully using the online websockets Pusher(didn't like it) and Scribble(amazing but downtime is too frequent since it's just one person running it).

我已遵循本教程 http://www.flynsarmy. com/2012/02/php-websocket-chat-application-2-0/在我的本地主机上,效果很好!

I've followed this tutorial http://www.flynsarmy.com/2012/02/php-websocket-chat-application-2-0/ on my localhost and it works great!

我想问的是,如何从上述文件中设置server.php,使其在在线webhost/共享服务器上作为websocket服务器运行?

What I wanted to ask is, how do I setup the server.php from the above file to run as a websocket server on an online webhost/shared server?

还是我需要获得一个VPS(如果是,那么,您推荐哪个?以及如何在那儿设置Websocket服务器,因为我以前从未真正使用过VPS!)

Or do I need to get a VPS (and if so, which one do you recommend and how can I setup the websocket server there as I've never really used a VPS before!)

非常感谢您阅读我的问题和回答.我在这里已阅读了有关套接字的所有其他问题/答案,但尚未找到上述问题的答案.希望我在这里找到它!

Thank you very much for reading my question and answering. I've read all other question/answers here regarding sockets but haven't been able to find the answer to my above questions yet. Hopefully I find it here!

推荐答案

这很棘手.

您需要执行server.php脚本,并且它永远都不会退出.如果您具有对共享服务器的SSH访问权限,则可以像在屏幕快照上一样执行该命令,并使用

You need to execute the server.php script and it needs to never exit. If you have an SSH access to your shared server, you could execute it just like they do on the screenshot and make it run as a background task using something like nohup:

$ nohup php server.php
nohup: ignoring input and appending output to `nohup.out'

调用此命令(使用SSH连接)后,您可以退出并且该过程将继续运行.脚本打印的所有内容都将存储在nohup.out中,您可以随时阅读.

After invoking this (using the SSH connection), you may exit and the process will continue running. Everything the script prints will be stored into nohup.out, which you can read at any time.

如果您没有SSH访问权限,并且实际执行PHP脚本的唯一方法是由于页面请求而通过Apache,那么您可以简单地使用浏览器进入该页面,而永远不会关闭浏览器.但是会有一天或另一天超时,您和Apache之间的连接将关闭,有效地停止了server.php脚本的执行.

If you don't have an SSH access, and the only way to actually execute a PHP script is through Apache as the result of a page request, then you could simply go to that page using a browser and never close the browser. But there will be a time out one day or another and the connection between you and Apache will close, effectively stopping the server.php script execution.

在以前的情况下,许多共享主机将不允许脚本无限期运行.您会注意到server.php中有此行:

And in those previous cases, a lot of shared hosts will not permit a script to run indefinitely. You will notice that there's this line in server.php:

set_time_limit(0);

这告诉PHP没有时间限制.如果主机使PHP在安全模式(其中很多人都这样做),那么您将无法使用set_time_limit并且时间限制可能在30秒或更短的时间内.

This tells PHP that there's no time limit. If the host made PHP run in safe mode (which a lot of them do), then you cannot use set_time_limit and the time limit is probably 30 seconds or even less.

是的,VPS可能是您最好的选择.现在,我自己没有所有权,也不知道什么是好价钱,但我会说 HostGator 看起来不错.

So yes, a VPS is probably your best bet. Now, I don't own one myself, and I don't know what's a good/bad price, but I'd say HostGator seems fine.

这篇关于究竟需要设置PHP Websocket服务器吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆