예제 #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) . "";