Files
kiri-core/test.php
T

51 lines
1.2 KiB
PHP
Raw Normal View History

2024-09-11 11:09:26 +08:00
<?php
ini_set('memory_limit','64GB');
use Swoole\Coroutine;
use Swoole\Coroutine\Http\Client;
use function Swoole\Coroutine\run;
function faker($page = 0)
{
$client = new Client('openapi.stupideyes.com', 443, true);
$client->get('/faker?offset=' . $page);
$client->close();
return json_decode($client->getBody(), true);
}
run(function () {
$offset = 1;
2024-09-11 11:10:15 +08:00
$success = 0;
2024-09-11 11:09:26 +08:00
for ($i = 1; $i <= 10000; $i++) {
$faker = faker($offset);
$offset++;
2024-09-11 11:10:15 +08:00
go(function () use ($faker, $offset, &$success) {
2024-09-11 11:09:26 +08:00
$socket = new Swoole\Coroutine\Http\Client('43.248.128.57', 14101);
$socket->upgrade("/ws?access_token=" . $faker['params']['token']);
if ($socket->connected) {
2024-09-11 11:10:15 +08:00
$success += 1;
2024-09-11 11:09:26 +08:00
while (true) {
$socket->recv();
// $socket->push('hello');
// var_dump($socket->recv());
Coroutine::sleep(0.1);
}
} else {
2024-09-11 11:10:15 +08:00
$success -= 1;
2024-09-11 11:09:26 +08:00
echo 'websocket fail: ' . socket_strerror($socket->errCode) . PHP_EOL;
}
});
Coroutine::sleep(0.1);
2024-09-11 11:10:15 +08:00
var_dump($success);
2024-09-11 11:09:26 +08:00
}
});