Table of Contents
回复讨论(解决方案)
Home Backend Development PHP Tutorial php socket服务端能不能在网页端开启?而不是只能用CLI模式开启

php socket服务端能不能在网页端开启?而不是只能用CLI模式开启

Jun 23, 2016 pm 01:52 PM
turn on Server model Can be used

最近在做基于php socket的聊天程序,但是遇到了个问题:
开启ws端口只能在CMD下用php server.php的方式来开启端口,并不能关闭该CMD命令行窗口,一旦关闭就断开了socket连接。
请问,能不能做到不用这样的方式来开启ws服务端,而成为在网页端来开启?怎么做?


回复讨论(解决方案)

可以从网站上开启,但需要注意以下问题:
1、因为端口不能重复打开,所以你必须保证 server.php 只会被运行一次
2、web 方式下的 php 是超时设置有效的,当然你需要设置成永不超时
3、web 服务器是有超时限制的,虽然时间比较长。应用程序长时间无数据输出,将会被挂起或中断
4、如果 server.php 间歇的做标准输出的话,可以解决 3 的问题。但会引发下一个问题
5、php 在向标准输出写的时候,会检查到请求源的连接是否畅通。如果请求源被关闭了,就会终止程序的运行
当然也提供有阻止这一默认行为的方法

其实命令窗口的存在并不是什么坏事,至少他可以表示 ws 服务器正在工作
另外 ws 服务器在运行时,你应该要把重要的日志信息打印在窗口中,以便实时监视运行情况

可以从网站上开启,但需要注意以下问题:
1、因为端口不能重复打开,所以你必须保证 server.php 只会被运行一次
2、web 方式下的 php 是超时设置有效的,当然你需要设置成永不超时
3、web 服务器是有超时限制的,虽然时间比较长。应用程序长时间无数据输出,将会被挂起或中断
4、如果 server.php 间歇的做标准输出的话,可以解决 3 的问题。但会引发下一个问题
5、php 在向标准输出写的时候,会检查到请求源的连接是否畅通。如果请求源被关闭了,就会终止程序的运行
当然也提供有阻止这一默认行为的方法

其实命令窗口的存在并不是什么坏事,至少他可以表示 ws 服务器正在工作
另外 ws 服务器在运行时,你应该要把重要的日志信息打印在窗口中,以便实时监视运行情况



非常感谢分析并回答!
因为在win下,CMD窗口一直在运行,并且不能关闭,一旦关闭将会停止运行socket服务,而这个窗口在桌面上显示人总会有种想关闭的冲动,或者一不小心就会关闭。所以才想出这样的狠招!
根据你的方法,设置了超时限制后,在网页端直接开启ws服务,在xampp的netstat中查看,创建的进程中,多出了个12345端口(设置的ws端口),而后面显示的name为httpd.exe,说明是由httpd.exe创建的,而前面php server.php在命令行下面创建的进程,则是由php.exe创建的,不知道这样有没有什么弊端?

没有什么弊端,尤其是在调试环境中
如果是正式的服务,那么在服务器桌面上多一个命令窗口有什么关系?谁也不会在服务器上做日常工作的

好的,再次感谢 

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Should memory integrity be turned on in win11? Should memory integrity be turned on in win11? Jan 06, 2024 am 08:53 AM

Like win10, win11 has introduced the memory integrity function to protect the system, but many friends don’t know what this function is used for. So, should win11 memory integrity be turned on? In fact, this has something to do with the computer system. Should memory integrity be turned on in win11: Answer: If the computer configuration is high, or it is just for daily office audio and video, it can be turned on; if our computer configuration is poor, or we are pursuing high performance, we should not turn it on. Introduction to win11 memory integrity: 1. The principle of memory integrity is that hardware virtualization creates an isolated environment. 2. It protects our system and memory security. 3. The disadvantage is that after turning on this function, it will run at any time, occupying memory and reducing performance. 4. And once it is turned on, it will be more troublesome to turn it off. It will definitely

What does WeChat's Do Not Disturb mode do? What does WeChat's Do Not Disturb mode do? Feb 23, 2024 pm 10:48 PM

What does WeChat Do Not Disturb mode mean? Nowadays, with the popularity of smartphones and the rapid development of mobile Internet, social media platforms have become an indispensable part of people's daily lives. WeChat is one of the most popular social media platforms in China, and almost everyone has a WeChat account. We can communicate with friends, family, and colleagues in real time through WeChat, share moments in our lives, and understand each other’s current situation. However, in this era, we are also inevitably faced with the problems of information overload and privacy leakage, especially for those who need to focus or

How to enable dlss? dlss opening strategy How to enable dlss? dlss opening strategy Mar 13, 2024 pm 07:34 PM

There is a dlss function in NVIDIA. After users turn on dlss, the game frame rate can be greatly improved. Therefore, many friends are asking the editor how to turn on dlss. First, make sure that the graphics card supports dlss and the game supports dlss, then you can enable it in the game. Let’s take a look at the specific tutorials below. Answer: DLSS generally needs to be opened in the game. To enable dlss, you must meet the conditions of the device and game. dlss is the "ray tracing effect", you can enter the game settings. Then go to the "Image or Graphics" settings. Then find "Ray Tracing Lighting" and click to open it. d

Do I need to enable GPU hardware acceleration? Do I need to enable GPU hardware acceleration? Feb 26, 2024 pm 08:45 PM

Is it necessary to enable hardware accelerated GPU? With the continuous development and advancement of technology, GPU (Graphics Processing Unit), as the core component of computer graphics processing, plays a vital role. However, some users may have questions about whether hardware acceleration needs to be turned on. This article will discuss the necessity of hardware acceleration for GPU and the impact of turning on hardware acceleration on computer performance and user experience. First, we need to understand how hardware-accelerated GPUs work. GPU is a specialized

How to enable Ethernet disabling in win10: Detailed steps How to enable Ethernet disabling in win10: Detailed steps Jan 03, 2024 pm 09:51 PM

Friends who use win10 system often ask how to enable Ethernet disabling. In fact, this operation is very simple. You need to enter the network settings to perform it. Next, I will take you to take a look. How to disable Ethernet in win10: 1. First, click the network connection icon in the lower right corner to open the network and Internet settings. 2. Then click on Ethernet. 3. Then click "Change Adapter Options". 4. At this point, you can right-click "Ethernet" and select Disable.

How to enable microphone permissions in Windows 10 How to enable microphone permissions in Windows 10 Jan 02, 2024 pm 11:17 PM

Recently, a friend found that the computer microphone cannot be turned on. Nowadays, both desktop computers and laptops have a microphone function. This also provides us with great convenience. However, many friends suddenly have microphones turned on during use. I found that my computer microphone has no sound. The editor below will teach you how to solve the problem by turning on the computer microphone. Let’s take a look at the details together. Methods for turning on the microphone permission in Windows 10: 1. When turning on the recorder under Windows 10, the prompt "You need to set the microphone in settings" pops up. 2. At this time, we can click the start button in the lower left corner of the screen and select the "Settings" menu item in the pop-up menu. 3. Click the "Privacy" icon in the Windows Settings window that opens. 4

Do Not Disturb Mode Not Working in iPhone: Fix Do Not Disturb Mode Not Working in iPhone: Fix Apr 24, 2024 pm 04:50 PM

Even answering calls in Do Not Disturb mode can be a very annoying experience. As the name suggests, Do Not Disturb mode turns off all incoming call notifications and alerts from emails, messages, etc. You can follow these solution sets to fix it. Fix 1 – Enable Focus Mode Enable focus mode on your phone. Step 1 – Swipe down from the top to access Control Center. Step 2 – Next, enable “Focus Mode” on your phone. Focus Mode enables Do Not Disturb mode on your phone. It won't cause any incoming call alerts to appear on your phone. Fix 2 – Change Focus Mode Settings If there are some issues in the focus mode settings, you should fix them. Step 1 – Open your iPhone settings window. Step 2 – Next, turn on the Focus mode settings

How to enable sleep mode in Win11 How to enable sleep mode in Win11 Jan 08, 2024 pm 02:45 PM

When we leave the computer for a long time but don’t want to shut it down, we can put the computer into sleep mode. However, after updating win11, we can’t find how to turn on the win11 sleep mode. In fact, we only need to turn it on in the control panel. How to enable hibernation mode in win11 Method 1: Use the start menu to click the bottom start menu, then click the power button to hibernate in it. Method 2: Use the Advanced User Menu 1. Search and open "Control Panel" in the search box on the desktop, click on the "Hardware and Sound" option, and click "Change what the power button does" under Power Options. 2. After entering, click "Change currently unavailable settings", and finally check "Hibernate" and save to execute the hibernation function. Method 3: Instructions

See all articles