Authored by ziy

修改说明

Showing 1 changed file with 138 additions and 15 deletions
1 -#Hood Docs  
2 -## CURL Concurrent  
3 -```php  
4 - use Hood\Concurrent;  
5 - $CurlMulti = Concurrent::curlMulti();  
6 - $CurlMulti->call('http://www.baidu.com',function ($curl_info, $curl_data, $callback_data) {  
7 - print_r($curl_info);  
8 - }, 1)->call('http://www.sogou.com',function ($curl_info, $curl_data, $callback_data) {  
9 - print_r($curl_info);  
10 - }, 2)->finish(); 1 +#Hood
  2 +
  3 +## 概述
  4 + 框架命名( Hood ) 发动机罩引擎罩来源于Yohood, 框架基于 Yaf 在数据层封装了Dao、Cache、Concurrent、Debug、Server 6个主要模块
  5 +框架以简单快捷为目的.
  6 +
  7 +## 安装
  8 + php版本要求 php 5.4+ 以上版本, 必要模块 Pdo_MySQL、Yaf、Yar
  9 + https://github.com/laruence/php-yaf
  10 + https://github.com/laruence/yar
  11 +
  12 + Yaf 文档
  13 + http://php.net/manual/zh/book.yaf.php
  14 +
  15 +## 配置文件
  16 + 1、数据库配置
  17 +
  18 + [mysql]
  19 + charset = UTF8
  20 + persistent = TRUE
  21 + collation = utf8_unicode_ci
  22 + timeout = 3
  23 + [database]
  24 + erp_admin.username = root
  25 + erp_admin.passwd = root
  26 + erp_admin.write = 127.0.0.1:3306
  27 + erp_admin.read = 192.168.1.106:3306
  28 + erp_admin.dbname = erp_admin
  29 +
  30 + hood.username = root
  31 + hood.passwd = root
  32 + hood.write = 127.0.0.1:3306
  33 + hood.read = 192.168.1.106:3306
  34 +
  35 + hood2.username = root
  36 + hood2.passwd = root
  37 + hood2.write = 127.0.0.2:3306
  38 + hood2.read = 192.168.2.106:3306
  39 +
  40 +
  41 +
  42 + 2、缓存配置
  43 + [memcached]
  44 + servers.hosts = 127.0.0.1:11211:90,127.0.0.1:11212:10
  45 + erp.hosts = 127.0.0.1:11211:90,127.0.0.1:11212:106
  46 + [redis]
  47 + servers.hosts = 127.0.0.1:6379
  48 +
  49 +
  50 +## Dao
  51 + Dao 提供主要如下方法
  52 +
  53 + 1、数据操作
  54 + insert、delete、update
  55 +
  56 + 2、查询数据
  57 + fetchAll、fetchRow、fetchPairs、fetchOne、fetchColumn、fetchObject、fetchClassRow、fetchClass、fetchAssoc、
  58 +
  59 + 3、其他设置
  60 + setModality 设置读写服务器
  61 + cache 缓存设置
  62 + tag 缓存标签
  63 + key 缓存key
  64 + expire 缓存过期时间
  65 +
  66 + 数据库操作借鉴Java的 mybatis 把SQL已配置文件形式存储
  67 + class SqlMap
  68 + {
  69 + const INSERT_DEMO = 'insert into demo (`username`,`email`) values (:username,:email)';
  70 + const UPDATA_DEMO_BY_ID = 'update demo set `username`=:username,`email`=:email where `id`=:id';
  71 + const SELECT_DEMO_BY_ID = 'select * from `demo` where id=:id';
  72 + }
  73 +
  74 + Insert
  75 + $this->dao()->insert(SqlMap::INSERT_DEMO, array(
  76 + 'username' => $username,
  77 + 'email' => $email
  78 + ))->lastInsertId();
  79 +
  80 + setModality(设置读写模式)
  81 + $this->dao()->setModality('read')->insert(SqlMap::INSERT_DEMO, array(
  82 + 'username' => $username,
  83 + 'email' => $email
  84 + ))->lastInsertId();
  85 +
  86 + update
  87 + $this->dao()->tag('demo_' . $id)->update(SqlMap::UPDATA_DEMO_BY_ID, array(
  88 + 'username' => $username,
  89 + 'email' => $email,
  90 + 'id' => $id
  91 + ))->rowCount();
  92 +
  93 + fetchClassRow
  94 + $this->dao()->tag('demo_' . $id)->key('demo_row')->expire(300)->setFetchClass('Models\Hood\Demo\Form')
  95 + ->fetchClassRow(SqlMap::SELECT_DEMO_BY_ID, array( 'id' => $id ));
  96 +
  97 + fetchAssoc
  98 + $this->dao()->tag('demo_' . $id)->key('demo_info')->fetchAssoc(SqlMap::SELECT_DEMO_BY_ID, array('id' => $id));
  99 +
  100 +
  101 +## Cache
11 102
  103 + $mc = hoodCache::Memcached($node, $child_node);
  104 + $mc->add($key , $val);
  105 + hoodCache::Memcached()->get($key);
  106 + hoodCache::Redis()->get($key);
  107 +
  108 +
  109 +## Concurrent
  110 +1、RPC ( PHP )
12 111
13 - $CurlMulti = Concurrent::curlMulti();  
14 - $CurlMulti->callRest('http://www.qin.com/index/demo', 'get', function ($curl_info, $curl_data, $callback_data) {  
15 - print_r($curl_data);  
16 - }, array('a' => 1))->finish();  
17 -```  
  112 + 1、普通接口数据请求
  113 + Concurrent::yarClient($uri)->getDemoInfoByID($id);
  114 +
  115 + 2、平行数据请求
  116 + Concurrent::yarConcurrent($uri)->calls('getDemoInfoByID', 1,function ($demoData) {
  117 + xxxx
  118 + })->calls('getDemoInfoByID', 2,function ($demoData) {
  119 + xxxxx
  120 + })->loop();
  121 +
  122 +2、CURL Concurrent
  123 +
  124 + ```php
  125 + use Hood\Concurrent;
  126 + $CurlMulti = Concurrent::curlMulti();
  127 + $CurlMulti->call('http://www.baidu.com',function ($curl_info, $curl_data, $callback_data) {
  128 + print_r($curl_info);
  129 + }, 1)->call('http://www.sogou.com',function ($curl_info, $curl_data, $callback_data) {
  130 + print_r($curl_info);
  131 + }, 2)->finish();
  132 +
  133 +
  134 + $CurlMulti = Concurrent::curlMulti();
  135 + $CurlMulti->callRest('http://www.qin.com/index/demo', 'get', function ($curl_info, $curl_data, $callback_data) {
  136 + print_r($curl_data);
  137 + }, array('a' => 1))->finish();
  138 + ```
  139 +
  140 +## Debug