简体   繁体   English

我可以在浏览器中的php中运行套接字服务器吗

[英]can i run socket server in php on the browser

hello I was wondering if I can run my PHP socket server on the browser I have a simple code 你好,我想知道我是否可以在浏览器上运行我的PHP socket服务器,我有一个简单的代码

$host = "0.0.0.0";
$somthing= 0;
$sock =  (AF_INET, SOCK_STREAM, 0);
socket_listen($sock);
while(true)
{
//do somthing
}

at the moment m using cmd to run the server can I use my web browser to do this so basically what I need is my browser to run the server and get replies from a client I can setup the client if someone can guide me on what to do so I can make it run on the server 在使用cmd运行服务器的那一刻,我可以使用Web浏览器来执行此操作吗,所以基本上我需要的是我的浏览器来运行服务器并获得客户端的答复,如果有人可以指导我如何操作,则可以设置客户端这样做,我可以使其在服务器上运行

Your browser can run your server script, look for "WAMP" solution (Windows, Apache, MySql (that you don't need in such case), PHP like wampserver ! 您的浏览器可以运行您的服务器脚本,寻找“ WAMP”解决方案(Windows,Apache,MySql(在这种情况下不需要),PHP像wampserver

For the second part, your client, you are going to need to use other technologie. 对于第二部分,您的客户,您将需要使用其他技术。 Ideally I would recommand looking to use javascript " websocket ". 理想情况下,我建议您使用javascript“ websocket ”。

Be aware, a php script can run for a limited amount of time by default, you can extend it . 请注意,默认情况下,PHP脚本可以运行有限的时间, 您可以对其进行扩展

I could also say that running the server script into a browser isn't ideal, you should run it in command line to avoid the script to stop running if you close the page (and also to avoid running the script more than once !). 我也可以说在浏览器中运行服务器脚本不是理想的选择,您应该在命令行中运行它,以免关闭页面后脚本停止运行(并且还要避免多次运行脚本!)。

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

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