Can the PHP socket server be opened on the Web side? Instead of only using CLI mode to open

Source: Internet
Author: User
Tags php server
Recently in a PHP socket-based chat program, but encountered a problem:
The open WS port can only open the port in PHP server.php under CMD, and cannot close the CMD command Line window, and once it is closed, the socket connection is disconnected.
Excuse me, can you do not use this way to open the WS server, and become on the web side to open? What do you do?


Reply to discussion (solution)

Can be opened from the Web site, but you need to be aware of the following issues:
1, because the port can not be opened repeatedly, so you must ensure that server.php will only be run once
2, the Web mode PHP is the time-out setting is valid, of course you need to set to never timeout
3, the Web server has a timeout limit, although the time is relatively long. Application has no data output for a long time and will be suspended or interrupted
4, if server.php intermittent to do standard output, can solve 3 of the problem. But it raises the next question.
5, PHP when writing to the standard output, will check the source of the request is connected to the smooth. If the request source is closed, the program's run is terminated
There is also a way to prevent this default behavior, of course

In fact, the existence of the command window is not a bad thing, at least he can indicate that the WS server is working
In addition, when the WS server is running, you should print the important log information in the window so that you can monitor the running situation in real time.

Can be opened from the Web site, but you need to be aware of the following issues:
1, because the port can not be opened repeatedly, so you must ensure that server.php will only be run once
2, the Web mode PHP is the time-out setting is valid, of course you need to set to never timeout
3, the Web server has a timeout limit, although the time is relatively long. Application has no data output for a long time and will be suspended or interrupted
4, if server.php intermittent to do standard output, can solve 3 of the problem. But it raises the next question.
5, PHP when writing to the standard output, will check the source of the request is connected to the smooth. If the request source is closed, the program's run is terminated
There is also a way to prevent this default behavior, of course

In fact, the existence of the command window is not a bad thing, at least he can indicate that the WS server is working
In addition, when the WS server is running, you should print the important log information in the window so that you can monitor the running situation in real time.



Thank you very much for analyzing and answering!
Because in win, the CMD window is running, and cannot be closed, once the shutdown will stop running the socket service, and this window on the desktop people will always have the urge to close, or accidentally shut down. That's why I came up with such a ruthless trick!
According to your method, after setting the time-out limit, the WS service is opened directly on the Web page, viewed in Xampp's netstat, and a 12345 port (set WS port) is created in the process. The name shown in the following is Httpd.exe, the description is created by Httpd.exe, and the previous PHP server.php created under the command line, the process is created by Php.exe, do not know if this has any drawbacks?

No drawbacks, especially in the debug environment
If it's a formal service, what's the relationship between one more command window on the server desktop? No one will do daily work on the server.

Okay, thanks again.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.