workerman icon indicating copy to clipboard operation
workerman copied to clipboard

Bug with multi server - they start listen port and get connection by another

Open webrobot1 opened this issue 1 year ago • 17 comments

Example:

  1. Start workerman Websocket server on port 8081 - all ok image

  2. Connect to server via another application (not workerman, client on local machine at c# language) - all ok image

  3. Start another workerman Websocket server on 8082 - all ok image

  4. Server point 1 (8081) create workerman AsyncTcpConnection to server from pint 3 (with port 8082) - all ok (doesnt matter wich server connect AsyncTcpConnection first) image

  5. Check after this 8081 port - not ok:

  • Master and Worker of server from point 3 (with 8082 port) start to listen 8081 port too (as Unix console say at the picture) image

  • additional this server from point 3 (port 8082) start to listen my client (what connect only to 8081 server from point 1) (as Lunix console say - you can see t the picture) image

  1. if i stop server from poit 1 (port 8081) server from point 3 still Listen the port 8081 and client from pint 2 now have Estabilished connection with server 3 (port 8082) image

webrobot1 avatar Jan 03 '23 18:01 webrobot1

Without point 2 situatian is same (server 8082 start to listen 8081 too after 8082 get AsyncTcpConnection from 8081 or another side of AsyncTcpConnection will - same result )

webrobot1 avatar Jan 03 '23 18:01 webrobot1

Well the problem is when start two workerman servers and some one (doesnt matter who of they) will open AsyncTcpConnection to another - two servers will start to listen the port of server what start firstly

webrobot1 avatar Jan 03 '23 18:01 webrobot1

As i check it is happen when i try use "exec" as command to start one Werkerman from another Workerman

webrobot1 avatar Jan 03 '23 21:01 webrobot1

look like doesnt matter what i try execute from "exec" command from workerman - new process open and listen the port already (i try exec filу with "Hello World" code and process already in Unix termonal listen the port)

webrobot1 avatar Jan 03 '23 22:01 webrobot1

look like it is problem in php. After "stream_socket_server" (in Worker.php) if you will try "fork" or "exec" or "shell_exec" command to open new proccess - it will listen the port too .

But it not open another server - it still one. I was try fork and "unlisten" it in new process but it unlisen in both process :)

Any idea how start new server from current in new process ?

webrobot1 avatar Jan 03 '23 23:01 webrobot1

Is the event extension installed?

walkor avatar Jan 04 '23 01:01 walkor

Is the event extension installed?

yes - Swoole. I try open create Timer with "exec" command to open new process with new workerman but result is same - new process will listen port too after it open (before eny code)

webrobot1 avatar Jan 04 '23 22:01 webrobot1

Workerman cannot change the features of PHP, such as the process inheritance listening socket when executing exec. As for the fork problem, some extensions do have such problems, for example, the event extension will affect the behavior of the other processes when you fork process and perform certain operations.

walkor avatar Jan 05 '23 02:01 walkor

Workerman cannot change the features of PHP, such as the process inheritance listening socket when executing exec. As for the fork problem, some extensions do have such problems, for example, the event extension will affect the behavior of the other processes when you fork process and perform certain operations.

i see...Is it possible save connection after Worker reload if it reloadable? Because if PHP work so NEW worker process (what will fork from master) will have same socket connection as he have before

webrobot1 avatar Jan 05 '23 02:01 webrobot1

or maybe if save connections addres (ip and port) possible use stream_socket_client for get resource for new worker

webrobot1 avatar Jan 05 '23 02:01 webrobot1

PHP can not do that

walkor avatar Jan 05 '23 02:01 walkor

PHP can not do that

but php already save the same socket at multi process, i think it is real...because then i disconnect from one process another still get connection of client (but client not connect exactly to this process, he connect to process what was close)

webrobot1 avatar Jan 05 '23 02:01 webrobot1

image at this pictires - it is two different workerman master +1 worker have same client to connect o same socket

webrobot1 avatar Jan 05 '23 02:01 webrobot1

may be if master process can collect connections too (as worker do) and after reload worker fork byself with these connections...

webrobot1 avatar Jan 05 '23 02:01 webrobot1

i will create experiment

webrobot1 avatar Jan 05 '23 02:01 webrobot1

PHP can not do that

well it is 2 way but it possible

  1. use https://www.php.net/manual/en/function.socket-wsaprotocol-info-export.php but it only for windows
  2. use https://www.php.net/manual/en/class.ffi.php and find resource of socket in memory (as you can see it stiil alive at another process) but need write code in "C" language

Well for this reason i think i will use Gataway in my project :)

webrobot1 avatar Jan 07 '23 12:01 webrobot1

and normaly open another workerman from current workerman only via http , because as i say open via fork exec system shell - will get port's listening in another process - php work like this

webrobot1 avatar Jan 07 '23 13:01 webrobot1