简体   繁体   English

在亚马逊 EC2 上运行 websocket 服务器

[英]Running websocket server on amazon EC2

I've written a web socket server that listens to a specific port.我编写了一个侦听特定端口的网络套接字服务器。 In order to run it I log in to EC2 instance with putty and run:为了运行它,我使用 putty 登录到 EC2 实例并运行:

php server.php

I was wondering if this is the only and the right way to do.我想知道这是否是唯一且正确的方法。 Normally copy my php files to the host via ftp would be enough, I don't understand why the php command needs to run the server.通常通过ftp将我的php文件复制到主机就足够了,我不明白为什么php命令需要运行服务器。 Any help is appreciated.任何帮助表示赞赏。

This question is not about any particular coding problem, so is considered off-topic in terms of StackOverflow.这个问题与任何特定的编码问题无关,因此在 StackOverflow 方面被认为是题外话。

The way PHP works - is just a script file. PHP 的工作方式 - 只是一个脚本文件。 Same as bash (.sh), python (.py), node.js (.js) or any other similar.与 bash (.sh)、python (.py)、node.js (.js) 或任何其他类似内容相同。

They all in fact have to be executed.事实上,他们都必须被处决。 In common world, Apache , nginx or any other web server will do execute those scripts for you for each request is made to web server.在普通世界中, Apachenginx或任何其他 Web 服务器将为您执行这些脚本,因为每个请求都是向 Web 服务器发出的。

As you are creating socket file, you need to create it yourself, as it creates one socket and php script will continue working as long as it will by it self.当您创建套接字文件时,您需要自己创建它,因为它会创建一个套接字并且 php 脚本将继续工作,只要它自己会。 It is not executed per each request.它不是针对每个请求执行的。 In fact make sure it is not executed by apache so do not put in usual website directory.事实上,确保它不是由 apache 执行的,所以不要放在通常的网站目录中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM