Skip to content
This repository has been archived by the owner on Nov 2, 2020. It is now read-only.

Commit

Permalink
refactor(Coroutine): Remove Coroutine Model
Browse files Browse the repository at this point in the history
1. Remove class Rid\Pool\ConnectionPool, Rid\{Database,Redis}\Coroutine,
   We now only keep permanent model.
2. Crontab: only print when function hit.
3. Remove class Rid\Http\Token Component.
4. Not remember empty session as invalid, just quick return false.
  • Loading branch information
Rhilip committed Jul 30, 2019
1 parent 6ac4ff4 commit 87b12e3
Show file tree
Hide file tree
Showing 13 changed files with 19 additions and 638 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- **Process:** Add custom Process Support
- **Redis:** Add mutiDelete() function for Redis
- **Tracker:** Add `retry in` field when failed
- **Tracker:** Move From Timer to Process
- **UserInfo:** Add Cache Lock of user access_{time,ip} update
- **ban:** Add table `ban_usernames` and `ban_emails`
- **csrf:** Add Csrf Support
Expand Down
39 changes: 0 additions & 39 deletions apps/commands/TimerCommand.php

This file was deleted.

7 changes: 4 additions & 3 deletions apps/components/Site.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@ protected function loadCurUser($grant = 'cookies')
protected function loadCurUserFromCookies()
{
$user_session_id = app()->request->cookie(Constant::cookie_name);
$user_id = app()->redis->zScore(Constant::mapUserSessionToId, $user_session_id);
if (false === $user_id) {
if (is_null($user_session_id)) return false; // quick return when cookies is not exist

if (false === $user_id = app()->redis->zScore(Constant::mapUserSessionToId, $user_session_id)) {
// First check cache
if (false === app()->redis->zScore(Constant::invalidUserSessionZset, $user_session_id)) {
// check session from database to avoid lost
Expand All @@ -126,7 +127,7 @@ protected function loadCurUserFromPasskey()
$passkey = app()->request->get('passkey');
$user_id = app()->redis->zScore(Constant::mapUserPasskeyToId, $passkey);
if (false === $user_id) {
if (app()->redis->zScore(Constant::invalidUserPasskeyZset, $passkey) !== false) {
if (app()->redis->zScore(Constant::invalidUserPasskeyZset, $passkey) === false) {
$user_id = app()->pdo->createCommand('SELECT `id` FROM `users` WHERE `passkey` = :passkey LIMIT 1;')->bindParams([
'passkey' => $passkey
])->queryScalar();
Expand Down
31 changes: 4 additions & 27 deletions apps/config/http_base.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php
/**
* rid-httpd 下运行的 HTTP 服务配置(常驻同步模式)
*
* Created by PhpStorm.
* User: Rhilip
* Date: 2018/11/26
Expand Down Expand Up @@ -81,31 +83,6 @@
'maxFileSize' => 0, // 最大文件尺寸
],

// Token
'token' => [
// 类路径
'class' => Rid\Http\Token::class,
// 保存处理者
'saveHandler' => [
// 类路径
'class' => Rid\Redis\RedisConnection::class,
// 主机
'host' => env('REDIS_HOST'),
// 端口
'port' => env('REDIS_PORT'),
// 数据库
'database' => env('REDIS_DATABASE'),
// 密码
'password' => env('REDIS_PASSWORD'),
],
// 保存的Key前缀
'saveKeyPrefix' => 'TOKEN:',
// 有效期
'expiresIn' => 604800,
// token键名
'name' => 'access_token',
],

// Session
'session' => [
// 类路径
Expand Down Expand Up @@ -160,7 +137,7 @@
// 数据库
'pdo' => [
// 类路径
'class' => Rid\Database\PDOConnection::class,
'class' => Rid\Database\Persistent\PDOConnection::class,
// 数据源格式
'dsn' => env('DATABASE_DSN'),
// 数据库用户名
Expand All @@ -177,7 +154,7 @@
// redis
'redis' => [
// 类路径
'class' => Rid\Redis\RedisConnection::class,
'class' => Rid\Redis\Persistent\RedisConnection::class,
// 主机
'host' => env('REDIS_HOST'),
// 端口
Expand Down
101 changes: 0 additions & 101 deletions apps/config/http_coroutine.php

This file was deleted.

21 changes: 0 additions & 21 deletions apps/config/http_permanent.php

This file was deleted.

2 changes: 1 addition & 1 deletion apps/config/httpd.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
'virtualHost' => [
'host' => '127.0.0.1',
'port' => 9501,
'configFile' => __DIR__ . '/http_permanent.php',
'configFile' => __DIR__ . '/http_base.php',
],

// 运行参数:https://wiki.swoole.com/wiki/page/274.html
Expand Down
6 changes: 3 additions & 3 deletions apps/process/CronTabProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use Rid\Base\Process;


class CronTabProcess extends Process
final class CronTabProcess extends Process
{

private $_print_flag = 1; // FIXME debug model on
Expand Down Expand Up @@ -67,7 +67,7 @@ public function run()
}
}
$end_time = time();
$this->print_log('This Cron Work period Start At ' . $start_time . ', Cost Time: ' . number_format($start_time - $end_time, 10) . 's, With ' . $hit . ' Jobs hits.');
if ($hit > 0) $this->print_log('This Cron Work period Start At ' . $start_time . ', Cost Time: ' . number_format($end_time - $start_time, 10) . 's, With ' . $hit . ' Jobs hits.');
}

protected function clean_expired_zset_cache() {
Expand All @@ -92,7 +92,7 @@ protected function clean_expired_zset_cache() {
foreach ($clean_list as $item) {
[$field, $msg] = $item;
$clean_count = app()->redis->zRemRangeByScore($field, 0, $timenow);
if ($clean_list) $this->print_log(sprintf($msg, $clean_count));
if ($clean_count > 0) $this->print_log(sprintf($msg, $clean_count));
}
}

Expand Down
8 changes: 6 additions & 2 deletions framework/Base/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class Process implements StaticInstanceInterface
private $sleep_time;
protected $_config;

public function run() {
public function run()
{

}

Expand All @@ -42,10 +43,13 @@ protected function resetSleepTime()
$this->setSleepTime($this->_config['sleep']);
}

final public function start($config) {
final public function start($config)
{
$this->_config = $config;
$this->resetSleepTime();

println('New Custom process `' . static::class . '` added.');

while (true) {
$this->run();
sleep($this->getSleepTime());
Expand Down
72 changes: 0 additions & 72 deletions framework/Database/Coroutine/PDOConnection.php

This file was deleted.

Loading

0 comments on commit 87b12e3

Please sign in to comment.