示例#1
0
文件: test.php 项目: hexingb/sim
<?php

require_once dirname(__FILE__) . '/sim.php';
$ip = '127.0.0.1';
$port = 8800;
$sim = new SimClient($ip, $port, -1);
$req = array('echo', '你好', 'hello world!', '[hi]', array('a', '中', '国', 'b'));
$sim->send($req);
$resp = $sim->recv();
var_dump($resp);
$total = 10000;
$stime = microtime(1);
for ($i = 0; $i < $total; $i++) {
    $s = sim_encode($req);
}
$speed = $total / (microtime(1) - $stime);
printf("encode speed: %d /s\n", $speed);
$total = 10000;
$stime = microtime(1);
for ($i = 0; $i < $total; $i++) {
    $sim->send($req);
    $resp = $sim->recv();
}
$speed = $total / (microtime(1) - $stime);
printf("speed: %d qps\n", $speed);
示例#2
0
文件: sim.php 项目: xzmagic/sim
 function send($data)
 {
     if (is_array($data)) {
         $s = sim_encode($data);
     } else {
         $s = $data;
     }
     if ($this->debug) {
         echo '> ' . str_replace(array("\r", "\n"), array('\\r', '\\n'), $s) . "\n";
     }
     try {
         while (true) {
             $ret = @fwrite($this->sock, $s);
             if ($ret === false || $ret === 0) {
                 $this->close();
                 throw new SimException('Connection lost');
             }
             $s = substr($s, $ret);
             if (strlen($s) == 0) {
                 break;
             }
             @fflush($this->sock);
         }
     } catch (Exception $e) {
         $this->close();
         throw new SimException($e->getMessage());
     }
     return $ret;
 }
示例#3
0
文件: test.php 项目: xzmagic/sim
require_once dirname(__FILE__) . '/sim.php';
$ip = '127.0.0.1';
$port = 8800;
$sim = new SimClient($ip, $port, -1);
$req = array('echo', '你好', "hello world!", '[hi]', array('a', '中', '国', 'b'));
$total = 10000;
$stime = microtime(1);
for ($i = 0; $i < $total; $i++) {
    $s = sim_encode($req);
}
$speed = $total / (microtime(1) - $stime);
printf("encode speed: %d /s\n", $speed);
$s = sim_encode($req);
$stime = microtime(1);
for ($i = 0; $i < $total; $i++) {
    $req = sim_decode($s);
}
$speed = $total / (microtime(1) - $stime);
printf("decode speed: %d /s\n", $speed);
$total = 10000;
$stime = microtime(1);
for ($i = 0; $i < $total; $i++) {
    $sim->send($req);
    $resp = $sim->recv();
}
$speed = $total / (microtime(1) - $stime);
printf("request speed: %d qps\n", $speed);
echo sim_encode($req) . "";
echo sim_encode($resp) . "";