update phpd subrepo

This commit is contained in:
Guobao Jiang 2014-03-05 18:19:33 +08:00
parent d80118b35f
commit 12495e10f8
9 changed files with 63 additions and 18 deletions

15
configure vendored
View File

@ -7,6 +7,21 @@
# USAGE # USAGE
# ./configure -- configure local machine # ./configure -- configure local machine
# ./configure -c -- collect local configure files # ./configure -c -- collect local configure files
#
# NOTE
# check $PATH include
# /usr/local/sbin
# /usr/local/bin
# /usr/sbin
# /usr/bin
# /sbin
# /bin
#
# AUTHOR
# Aborn Jiang (aborn.jiang@gmail.com)
#
# VERSION
# v0.1 2014-03-04
############################################################### ###############################################################
ABSPATH=$(dirname $0) ABSPATH=$(dirname $0)
cd ${ABSPATH} cd ${ABSPATH}

View File

@ -2,8 +2,8 @@
require_once('mysql2redis.php'); require_once('mysql2redis.php');
$items_number=2000000; $items_number=2000000;
$tab_redis = new mysql2redis(); $tab_redis = new mysql2redis();
$tab_redis->setTBname('bench');
$tab_redis->setDBname('test'); $tab_redis->setDBname('test');
$tab_redis->setTBname('bench');
$tab_redis->bench($items_number); $tab_redis->bench($items_number);
$tab_redis->bench($items_number, 'bench_no_index'); $tab_redis->bench($items_number, 'bench_no_index');
?> ?>

View File

@ -33,6 +33,11 @@ class dbops {
} }
} }
public function tabsize($sql)
{
return $this->mysqli->query($sql);
}
public function query($sql) public function query($sql)
{ {
if ($this->connect()) { if ($this->connect()) {

View File

@ -25,7 +25,8 @@ class iredis
public function __construct() public function __construct()
{ {
$this->redis = new redis(); $this->redis = new redis();
$this->redis->pconnect($this->redis_server, $this->redis_port); $this->redis->connect($this->redis_server, $this->redis_port);
## $this->redis->pconnect($this->redis_server, $this->redis_port);
} }
public function __destruct() public function __destruct()
@ -58,6 +59,11 @@ class iredis
{ {
$this->redis->close(); $this->redis->close();
} }
public function select($database=0)
{
$this->redis->select($database);
}
public function append($key, $value) public function append($key, $value)
{ {

View File

@ -29,9 +29,10 @@ class looptest
$ops = new dbops(); $ops = new dbops();
$ops->setTBname($tbname); $ops->setTBname($tbname);
$ops->setDBname($dbname); $ops->setDBname($dbname);
##$start=$i*rand(1,950); # more then 2w
$start=$i*128; $start=$i*128;
$conditions = sprintf("idx > %d and idx < %d;", $conditions = sprintf ("idx > %d and idx < %d;",
$start, $start + 1000); $start, $start+1000);
$sql = sprintf("select * from %s where %s", $sql = sprintf("select * from %s where %s",
$tbname, $conditions); $tbname, $conditions);
$data = $ops->query($sql); $data = $ops->query($sql);

View File

@ -6,6 +6,7 @@
#require_once('mysql_info.php'); #require_once('mysql_info.php');
require_once('dbops.php'); require_once('dbops.php');
require_once('iredis.php');
echo "数据库测试页面\n <br/>"; echo "数据库测试页面\n <br/>";
date_default_timezone_set('PRC'); date_default_timezone_set('PRC');
@ -60,10 +61,11 @@ echo "<br/>";
echo "<br/>"; echo "<br/>";
echo "follow test redis:"; echo "follow test redis:";
$redis = new redis(); $redis = new iredis();
$result = $redis->connect('127.0.0.1', 6379); $result = $redis->configure('127.0.0.1', 6379);
#var_dump($result); //结果bool(true) #var_dump($result); //结果bool(true)
$redis->set('test', 'hello world!'); #$redis->set('test', 'hello world!');
#$redis->select(1);
echo $redis->get('test'); echo $redis->get('test');
?> ?>

View File

@ -24,7 +24,6 @@ class mysql2redis
public function __construct() public function __construct()
{ {
$this->iredis = new iredis(); $this->iredis = new iredis();
$this->mysql = new dbops(); $this->mysql = new dbops();
} }
@ -34,15 +33,23 @@ class mysql2redis
$this->mysql->close(); $this->mysql->close();
} }
public function tabsize($tabname)
{
$sql = sprintf("select idx, count(idx) as total from %s", $tabname);
$rs=$this->mysql->tabsize($sql);
$no=$rs->fetch_row();
return $no[1];
}
public function bench($items_number, $bench='bench') public function bench($items_number, $bench='bench')
{ ## 测试前创建数据表格操作 { ## 测试前创建数据表格操作
## $del_sql = sprintf("delete from %s where idx>0;", $bench); ## $del_sql = sprintf("delete from %s where idx>0;", $bench);
$del_sql = sprintf("delete from %s;", $bench); $del_sql = sprintf("delete from %s;", $bench);
$this->mysql->query($del_sql); $this->mysql->query($del_sql);
## $this->mysql->query("select * from bench;"); ## $this->mysql->query("select * from bench;");
for ($i=0; $i < $items_number; $i++) for ($i=0; $i < $items_number; $i++)
{ {
$value = sprintf("(%d,\"name%d\",\"%s\")", $i, $i, $bench); $value = sprintf("(%d,%d,\"name%d\",\"%s\")", $i, $i+1, $i, $bench);
$insert_sql = sprintf("insert into %s values%s;",$bench,$value); $insert_sql = sprintf("insert into %s values%s;",$bench,$value);
$this->mysql->query($insert_sql); $this->mysql->query($insert_sql);
} }

View File

@ -10,21 +10,26 @@ require_once('looptest.php');
#$tbname="account"; #$tbname="account";
#$tbname="temp"; #$tbname="temp";
$tbname="bench_no_index"; #$tbname="bench_no_index";
#$tbname="bench"; #$tbname="bench";
$dbname="test"; $dbname="test";
$loop_times=10; $loop_times=20;
$items_number=30000;
$tab_redis = new mysql2redis(); $tab_redis = new mysql2redis();
$tab_redis->setTBname($tbname); $tab_redis->setTBname($tbname);
$tab_redis->setDBname($dbname); $tab_redis->setDBname($dbname);
# $tab_redis->bench($items_number, $tbname); ## 创建数据表格 # $tab_redis->bench($items_number, $tbname); ## 创建数据表格
$sql = sprintf("select * from %s where idx > 29000 and idx < 30000", $tbname); $startI=9000; ## 29000
$endI=10000; ## 30000
$sql = sprintf("select * from %s where idx > %d and idx < %d", $tbname, $startI, $endI);
$tab_redis->mysql2redis($tbname, $sql); $tab_redis->mysql2redis($tbname, $sql);
######### 下面为测试调用 ######### 下面为测试调用
echo "</br>";
echo $sql;
echo "</br>";
$lptest = new looptest(); $lptest = new looptest();
$lptest->configure($tbname, $dbname); $lptest->configure($tbname, $dbname);
@ -41,13 +46,15 @@ echo "<br/>"; echo "<br/>";
echo "[redis对应表".$tbname." ]执行 $loop_times 次循环(单次时间 ms)为:"; echo "[redis对应表".$tbname." ]执行 $loop_times 次循环(单次时间 ms)为:";
echo ($rstime/$loop_times)*1000; echo ($rstime/$loop_times)*1000;
$items_number = $tab_redis->tabsize($tbname);
echo "<br/>"; echo "<br/>"; echo "<br/>"; echo "<br/>";
echo "item=$items_number [数据库]/[redis]比值为:"; echo "item=$items_number [数据库]/[redis]比值为:";
echo $dbtime/$rstime; echo $dbtime/$rstime;
######### 下面为测试输出 ######### 下面为测试输出
#$tab_redis->print_mysql_table(); #$tab_redis->print_mysql_table($tbname);
# var_dump($data); # var_dump($data);
?> ?>

View File

@ -4,16 +4,18 @@ DROP TABLE IF EXISTS bench_no_index;
CREATE TABLE bench ( CREATE TABLE bench (
idx INT(10) NOT NULL PRIMARY KEY, idx INT(10) NOT NULL PRIMARY KEY,
age INT(10),
name VARCHAR(20) NOT NULL, name VARCHAR(20) NOT NULL,
des VARCHAR(100) NOT NULL des VARCHAR(100) NOT NULL
); );
insert into bench value(0,'000','shanghai'); insert into bench value(0,0,'000','shanghai');
CREATE TABLE bench_no_index ( CREATE TABLE bench_no_index (
idx INT(10) NOT NULL, idx INT(10) NOT NULL,
age INT(10),
name VARCHAR(20) NOT NULL, name VARCHAR(20) NOT NULL,
des VARCHAR(100) NOT NULL des VARCHAR(100) NOT NULL
); );
insert into bench_no_index value(0,'000','shanghai'); insert into bench_no_index value(0,0,'000','shanghai');