diff --git a/doc/fu-wu-zhong-xin/yi-bu-http-server-zhong-shi-yong-fu-wu.md b/doc/fu-wu-zhong-xin/yi-bu-http-server-zhong-shi-yong-fu-wu.md index 967e05c..32715e5 100644 --- a/doc/fu-wu-zhong-xin/yi-bu-http-server-zhong-shi-yong-fu-wu.md +++ b/doc/fu-wu-zhong-xin/yi-bu-http-server-zhong-shi-yong-fu-wu.md @@ -30,7 +30,7 @@ $callId1 = $service->addCall("User::getUsersCache", ['ids' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]); $callId2 = $service->addCall("User::getUser", ['id' => 1]); $res = (yield $service->multiCall()); - + dump($res[$callId1]); dump($res[$callId2]); ``` diff --git a/doc/tong-bu-fu-wu/dao.md b/doc/tong-bu-fu-wu/dao.md index 9132205..324090d 100644 --- a/doc/tong-bu-fu-wu/dao.md +++ b/doc/tong-bu-fu-wu/dao.md @@ -1,4 +1,91 @@ ### Dao +> ##### 框架内部会做断线重连,失败3次后将进行重连操作 + +#### 文档参考:[Doctrine DBAL’s documentation](http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/index.html) + +##### $this->getDefault\(\) + +> ##### 获取默认服务器连接,返回\Doctrine\DBAL\Connection对象 + +##### $this->getRead\($name = null\) + +> ##### 获取读服务器连接,若name不填,随机读取。 + +##### $this->getWrite\($name = null\) + +> ##### 获取写服务器连接,若name不填,随机读取。 + +##### $this->getAllRead\(\) + +> 获取所有读服务器的连接 + +##### $this->getAllWrite\(\) + +> 获取所有写服务器的连接 + +##### $this->querySql\($sql, $type, $name = null\) + +> \* @param sql +> +> \* @param type\[write\|all\_write\|read\|all\_read\|default\] +> +> \* @param name + +##### 具体业务中使用: + +``` + +namespace src\Service\User\Dao\Impl; + +use Dao; +use src\Service\User\Dao\UserDao; + +class UserDaoImpl extends Dao implements UserDao +{ + protected $table = "user"; + + public function getUser($id) + { + $queryBuilder = $this->getDefault()->createQueryBuilder(); + $queryBuilder + ->select("*") + ->from($this->table) + ->where('id = ?') + ->setParameter(0, $id); + + return $queryBuilder->execute()->fetch(); + } + + public function addUser($user) + { + $conn = $this->getDefault(); + $affected = $conn->insert($this->table, $user); + if ($affected <= 0) { + return fasle; + } + return $conn->lastInsertId(); + } + + public function getUserByMobile($mobile) + { + $queryBuilder = $this->getDefault()->createQueryBuilder(); + $queryBuilder + ->select("*") + ->from($this->table) + ->where('mobile = ?') + ->setParameter(0, $mobile); + + return $queryBuilder->execute()->fetch(); + } + + public function updateUserPassword($userId, $password) + { + return $this->getDefault()->update($this->table, ['password' => $password], ['id' => $userId]); + } +} + +``` + diff --git a/doc/tong-bu-fu-wu/filecachewen-jian-huan-cun-lei.md b/doc/tong-bu-fu-wu/filecachewen-jian-huan-cun-lei.md index cf975ae..d48fcae 100644 --- a/doc/tong-bu-fu-wu/filecachewen-jian-huan-cun-lei.md +++ b/doc/tong-bu-fu-wu/filecachewen-jian-huan-cun-lei.md @@ -1,6 +1,26 @@ ### FileCache -### +##### 文件形式的缓存 + +#### FileCache::get\($cacheName, $cacheDir = false\) + +``` +use FileCache; + +FileCache::get('test.php'); +FileCache::get('test.php', 'runtime/cache/test/'); +``` + +#### FileCache::set\($cacheName, $data, $cacheDir = false, $flag = false\) + +``` +use FileCache; + +//默认路径是放在runtime/logs/service +FileCache::set('test.php', ['testdfata' => 'datadata']); +//指定路径 +FileCache::set('test.php', ['testdfata' => 'datadata'], 'runtime/cache/test/', FILE_APPEND); +``` diff --git a/doc/tong-bu-fu-wu/logri-zhi-lei.md b/doc/tong-bu-fu-wu/logri-zhi-lei.md index ccf549c..8225048 100644 --- a/doc/tong-bu-fu-wu/logri-zhi-lei.md +++ b/doc/tong-bu-fu-wu/logri-zhi-lei.md @@ -1,4 +1,25 @@ ### Log +#### 默认路径存放于runtime/logs/service + +```php + + Log::debug('123',['user'=>1]); + Log::info('123',['user'=>1]); + Log::notice('123',['user'=>1]); + Log::warning('123',['user'=>1]); + Log::error('123',['user'=>1]); + Log::critical('123',['user'=>1]); + Log::alert('123',['user'=>1]); + Log::emergency('123',['user'=>1]); + + //默认model是web.app,也可以自定义 + Log::emergency('123',['user'=>1],'web.admin'); +``` + +## + + + diff --git a/doc/tong-bu-fu-wu/rediscache.md b/doc/tong-bu-fu-wu/rediscache.md index a5659fc..7877e49 100644 --- a/doc/tong-bu-fu-wu/rediscache.md +++ b/doc/tong-bu-fu-wu/rediscache.md @@ -1,4 +1,27 @@ ### Cache +##### 目前只支持了Redis得cache,使用请在config/database.php配置中配置'cache' => 'redis', + +```php + use Cache; + //key value expireTime + Cache::set('ha', 123, 60); + //也可以这样 + Cache::redis() -> set('haa', 123, 60); + + Cache::get('ha'); + Cache::mGet(['ha', 'aa']); + Cache::hSet($hashKey, $key, $data, $expireTime); + Cache::hGet($hashKey, $key); + Cache::hDel($hashKey, $key); + Cache::hDel($hashKey); + + //现在的类库方法还未扩展完全,目前只有以上方法 +``` + +* ##### 你可以使用Cache::redis\(\) 获取redis实例,这是一个PhpRedis的实例,api地址\([https://github.com/phpredis/phpredis\](https://github.com/phpredis/phpredis\)\) + + + diff --git a/doc/tong-bu-fu-wu/service.md b/doc/tong-bu-fu-wu/service.md index c816a60..06dfdbc 100644 --- a/doc/tong-bu-fu-wu/service.md +++ b/doc/tong-bu-fu-wu/service.md @@ -1,4 +1,63 @@ ### Service服务 +* > #### Service服务是配合服务中心来实现服务化的。每个服务可以单独启动一个server,处理请求。 + > + > #### 在开发Service模块时候,同样要注意内存释放问题。并且不可以使用异步服务,此模块是以同步方式执行的。 + > + > #### 所以说,你可以用传统的方式来编写服务接口,当然你也可以使用内置的一些异步task方法来实现map-reduce,提升接口吞吐。 + +#### 1.开启服务如执行 app/service user,会开放服务下面指定开放模块所有公有函数调用 + +#### 2.使用Console控制台,自动初始化服务 + +``` +app/console generate:service demo +``` + +#### 3.简单介绍一下生成的服务目录结构 + +* User \(示例\) + + * Dao + + * Impl \(数据层实现的接口\) + + * UserDaoImpl.php\(接口实现\) + + * UserDao.php\(接口\) + + * Service + + * Impl (服务层实现的接口) + + * UserServiceImpl.php\(接口的实现\) + + * Rely (定义服务之间的依赖关系) + + * UserService.php\(接口\) + +#### Service类 + +$this->createDao\($serviceName\) + +> 实例化一个dao类 + +$this->createService\($serviceName\) + +> 实例化一个service类 + +``` +public function getUserDao() +{ + return $this->createDao("User:User"); +} + + +public function getUserProfileService() +{ + return $this->createService("User:UserProfile"); +} +``` +