简体   繁体   English

两个脚本如何同时使用同一端口?

[英]How can two scripts use the same port at the same time?

I'm trying to set up a "server" script in PHP, which should run for a limited amount of time in the background. 我正在尝试在PHP中设置“服务器”脚本,该脚本应在后台运行有限的时间。 But multiple instances of this script may run at the same time. 但是此脚本的多个实例可以同时运行。 Unfortunately fsockopen() doesn't let me use the same port at the same time by two different scripts, so others fail in error :( 不幸的是fsockopen()不允许我通过两个不同的脚本同时使用同一端口,因此其他脚本会失败:(

Is there any way around this? 有没有办法解决?

fsockopen用于客户端套接字,您无法使用fsockopen启动服务器以侦听特定端口

PHP doesnot support multi-threading , but there are alternatives to it, not the best but in slang word- "workable". PHP不支持多线程 ,但是它有替代方法,不是最好的,而是but语“可行”。

And to listen on specific port using php , Use socket_listen , socket_bind , socket_create , etc., functions of php, you may have a look on stream_select functions too... if that helps. 要使用php侦听特定端口,请使用php函数的socket_listensocket_bindsocket_create等,您也可以看看stream_select函数...如果有帮助。

Recommended page Parallel processing in PHP 推荐页面PHP中的并行处理

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

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