From 47e0aafd0b178ae34536d85343f08e48dc8c6c36 Mon Sep 17 00:00:00 2001 From: voldemar Date: Mon, 14 Mar 2016 17:13:34 +0200 Subject: [PATCH] perfomance test + fix composer require --- Test.php | 26 +++++++++++++++++++++++++- composer.json | 5 +++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/Test.php b/Test.php index f0972df..395c6f2 100644 --- a/Test.php +++ b/Test.php @@ -10,7 +10,16 @@ public function __construct($config) { } public function start() { - for ($i=0, $j=0; $i<=1500; $i++) { + for ($i=0; $i < $this->config['workers']-1; $i++) { + $pid = pcntl_fork();//создаём форк + if ($pid == -1) { + die("error: pcntl_fork\r\n"); + } elseif (!$pid) {//воркер + break; + } + } + + for ($i=0, $j=0; $i<=$this->config['clients']; $i++) { $client = @stream_socket_client($this->config['websocket'], $errorNumber, $errorString, 1); if ($client) { @@ -22,6 +31,7 @@ public function start() { $i--; $j++; if ($j && $j % 100 == 0) echo "success: $i, failure: $j\r\n"; + if ($j == $this->config['clients']) break; } } @@ -48,7 +58,21 @@ public function start() { fwrite($this->clients[rand(0, 1000)], $data); }*/ } + } else { + break; } } } +} + +if (!empty($argv[1]) && $argv[1] == 'start' && !empty($argv[2]) && + !empty($argv[3]) && $argv[3] >= 1 && $argv[3] <= 1000 && + !empty($argv[4]) && $argv[4] >= 1 && $argv[4] <= 1000 +) { + $config = [ + 'websocket' => $argv[2], + 'clients' => intval($argv[3]), + 'workers' => intval($argv[4]), + ]; + (new Test($config))->start(); } \ No newline at end of file diff --git a/composer.json b/composer.json index 8fe0345..061a42b 100644 --- a/composer.json +++ b/composer.json @@ -3,9 +3,10 @@ "description": "simple php websocket server with examples and demo: simple chat (single daemon) - http://sharoid.ru/chat.html , pro chat (master + worker) - http://sharoid.ru/chat2.html , simple game - http://sharoid.ru/game.html", "keywords": ["websocket", "server", "examle", "demo", "chat", "game", "socket_select", "event", "libevent", "yii", "laravel"], "require": { - "php": ">=5.3.0" + "php": ">=5.3.0", + "ext-mbstring": "*" }, - "version": "4.1.0", + "version": "4.2.0", "license": "MIT", "homepage": "http://sharoid.ru/game.html", "authors": [