Skip to content

Commit

Permalink
perfomance test + fix composer require
Browse files Browse the repository at this point in the history
  • Loading branch information
voldemar committed Mar 14, 2016
1 parent 461fb23 commit 47e0aaf
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
26 changes: 25 additions & 1 deletion Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}
}

Expand All @@ -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();
}
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down

0 comments on commit 47e0aaf

Please sign in to comment.