HEX
Server: Apache/2.4.59 (Debian)
System: Linux keymana 4.19.0-21-cloud-amd64 #1 SMP Debian 4.19.249-2 (2022-06-30) x86_64
User: lijunjie (1003)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: //home/lijunjie/swoole-cli/swoole-src-4.8.13/examples/websocket/client.php
<?php
require __DIR__ . '/../../tests/include/api/swoole_websocket_server/websocket_client.php';
$opt = getopt("c:n:k:");
print_r($opt);
if (empty($opt['c']) || empty($opt['n'])) {
    echo "examples:  php client.php -c 100 -n 10000" . PHP_EOL;
    return;
}
$clients = $opt['c'];
$count = $opt['n'];
$size = empty($opt['k']) ? 0 : $opt['k'];


$host = '127.0.0.1';
$prot = 9501;

$client = new WebSocketClient($host, $prot);
$data = $client->connect();
//echo $data;
$data = "data";
if (!empty($size)) {
    $data = str_repeat("A", $size * 1024);
}
for ($i = 0; $i < $count; $i++) {
    $client->send("hello swoole, number:" . $i . " data:" . $data);
    $recvData = "";
    //while(1) {
    $tmp = $client->recv();
    if (empty($tmp)) {
        break;
    }
    $recvData .= $tmp;
    //}
    echo $recvData . "size:" . strlen($recvData) . PHP_EOL;
}
echo PHP_EOL . "======" . PHP_EOL;
sleep(1);
echo 'finish' . PHP_EOL;