Пример #1
0
if (!isset($arguments['concurrent']) && !isset($arguments['connect']) && !isset($arguments['time'])) {
    die("usage: benchmark.php -c {num of clients} -C {address} -T {timed testing}");
}
define('NUM_OF_CLIENTS', $arguments->get('concurrent'));
define('CONNECT', $arguments->get('connect'));
define('TIME_TO_TESTING', $arguments->get('time') * 1000);
define('LENGTH', $arguments->get('length', 100));
printf("clients %d, connect %s, time to testing %f sec, length %d\n", NUM_OF_CLIENTS, CONNECT, TIME_TO_TESTING / 1000, LENGTH);
// ready
$recv = [];
$clients = [];
$poller = new Poller();
$msg = str_repeat('-', LENGTH);
for ($i = 0; $i < NUM_OF_CLIENTS; ++$i) {
    $client = new ClientApp();
    $client->setSndHwm(1000000);
    $client->setRcvHwm(1000000);
    $client->connect(CONNECT, null, true);
    $client->setRecvTimeout(200);
    $client->setSendTimeout(200);
    $id = $poller->registerReadable($client);
    $clients[$id] = $client;
    $recv[$id] = 0;
}
$sending = 0;
$recving = 0;
$start = mt();
foreach ($clients as $id => $client) {
    $client->send($msg);
}
while (mt() - $start < TIME_TO_TESTING) {