1--TEST-- 2swoole_server: 10k connections 3--SKIPIF-- 4<?php 5require __DIR__ . '/../include/skipif.inc'; 6require __DIR__ . '/../include/config.php'; 7if ((int)`ulimit -n 2>&1` < MAX_CONCURRENCY_MID * MAX_REQUESTS) { 8 skip('ulimit -n failed'); 9} 10?> 11--FILE-- 12<?php 13require __DIR__ . '/../include/bootstrap.php'; 14$count = 0; 15$client_map = []; 16$pm = new SwooleTest\ProcessManager; 17$pm->parentFunc = function () use ($pm) { 18 for ($c = MAX_CONCURRENCY_MID; $c--;) { 19 go(function () use ($pm, $c) { 20 for ($n = MAX_REQUESTS; $n--;) { 21 global $count, $client_map; 22 $client = new Swoole\Coroutine\Client(SWOOLE_SOCK_TCP); 23 $client_map["{$c}.{$n}"] = $client; 24 if ($client->connect('127.0.0.1', $pm->getFreePort(), -1)) { 25 if (Assert::assert($client->recv() === 'Hello Swoole!')) { 26 if (++$count === MAX_CONCURRENCY_MID * MAX_REQUESTS) { 27 var_dump($count); 28 echo "DONE\n"; 29 $client_map = []; 30 $pm->kill(); 31 } 32 continue; 33 } 34 } else { 35 echo "ERROR\n"; 36 $pm->kill(); 37 exit; 38 } 39 } 40 }); 41 } 42 register_shutdown_function(function () { 43 global $client_map; 44 foreach ($client_map as $client) { 45 $client->close(); 46 } 47 }); 48}; 49$pm->childFunc = function () use ($pm) { 50 $server = new Swoole\Server('127.0.0.1', $pm->getFreePort(), SWOOLE_BASE); 51 $server->set([ 52 "worker_num" => swoole_cpu_num() * 2, 53 'log_file' => '/dev/null', 54 'max_connection' => MAX_CONCURRENCY_MID * MAX_REQUESTS 55 ]); 56 $server->on("WorkerStart", function (Swoole\Server $serv) use ($pm) { 57 $pm->wakeup(); 58 }); 59 $server->on('connect', function (Swoole\Server $server, int $fd) { 60 global $count; 61 $count++; 62 $server->send($fd, 'Hello Swoole!'); 63 }); 64 $server->on('receive', function (Swoole\Server $serv, $fd, $rid, $data) { }); 65 $server->start(); 66}; 67$pm->childFirst(); 68$pm->run(); 69?> 70--EXPECTF-- 71int(%d) 72DONE 73