@@ -11,13 +11,12 @@ use Swoole\Coroutine\Socket;
1111use Swoole \Event ;
1212
1313$ pm = new ProcessManager ();
14- $ port = get_one_free_port ();
15- $ pm ->parentFunc = function ($ pid ) use ($ pm , $ port ) {
14+ $ pm ->parentFunc = function ($ pid ) use ($ pm ) {
1615 $ socket = new Socket (AF_INET , SOCK_STREAM , 0 );
1716 Assert::isInstanceOf ($ socket , Socket::class);
1817 Assert::same ($ socket ->errCode , 0 );
19- go (function () use ($ socket , $ port ) {
20- Assert::assert ($ socket ->connect ('localhost ' , $ port ));
18+ go (function () use ($ socket , $ pm ) {
19+ Assert::assert ($ socket ->connect ('localhost ' , $ pm -> getFreePort () ));
2120 $ i = 0.000 ;
2221 while (true ) {
2322 $ socket ->send ('hello ' );
@@ -35,9 +34,9 @@ $pm->parentFunc = function ($pid) use ($pm, $port) {
3534 Event::wait ();
3635};
3736
38- $ pm ->childFunc = function () use ($ pm, $ port ) {
37+ $ pm ->childFunc = function () use ($ pm ) {
3938 $ socket = new Socket (AF_INET , SOCK_STREAM , 0 );
40- Assert::assert ($ socket ->bind ('127.0.0.1 ' , $ port ));
39+ Assert::assert ($ socket ->bind ('127.0.0.1 ' , $ pm -> getFreePort () ));
4140 Assert::assert ($ socket ->listen (128 ));
4241 go (function () use ($ socket , $ pm ) {
4342 $ pm ->wakeup ();
0 commit comments