-
-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
45 changed files
with
1,065 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
require __DIR__ . '/imi.php'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
use Imi\App; | ||
use Imi\Util\Args; | ||
use Imi\Util\File; | ||
|
||
Args::init(); | ||
|
||
$namespace = Args::get('appNamespace'); | ||
if(null === $namespace) | ||
{ | ||
$config = include File::path(dirname($_SERVER['SCRIPT_NAME'], 2), 'config/config.php'); | ||
$namespace = $config['namespace']; | ||
} | ||
|
||
App::run($namespace); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,8 @@ | |
'Imi\Model', | ||
'Imi\Task', | ||
'Imi\Tool', | ||
'Imi\Process', | ||
'Imi\HotUpdate', | ||
], | ||
'atomics' => [ | ||
'session' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
namespace Imi\HotUpdate; | ||
|
||
use Imi\App; | ||
use Imi\Util\Imi; | ||
use Imi\Util\Coroutine; | ||
use Imi\Bean\BeanFactory; | ||
use Imi\Process\BaseProcess; | ||
use Imi\Bean\Annotation\Bean; | ||
use Imi\Process\Annotation\Process; | ||
|
||
/** | ||
* @Bean("hotUpdate") | ||
* @Process("hotUpdate") | ||
*/ | ||
class HotUpdateProcess extends BaseProcess | ||
{ | ||
/** | ||
* 监视器类 | ||
* @var \Imi\HotUpdate\Monitor\BaseMonitor | ||
*/ | ||
protected $monitorClass = \Imi\HotUpdate\Monitor\FileMTime::class; | ||
|
||
/** | ||
* 每次检测时间间隔,单位:秒(有可能真实时间会大于设定的时间) | ||
* @var integer | ||
*/ | ||
protected $timespan = 1; | ||
|
||
/** | ||
* 包含的路径 | ||
* @var array | ||
*/ | ||
protected $includePaths = []; | ||
|
||
/** | ||
* 排除的路径 | ||
* @var array | ||
*/ | ||
protected $excludePaths = []; | ||
|
||
/** | ||
* 默认监视路径 | ||
* @var array | ||
*/ | ||
protected $defaultPath = null; | ||
|
||
/** | ||
* 是否开启热更新,默认开启 | ||
* @var boolean | ||
*/ | ||
protected $status = true; | ||
|
||
public function run(\Swoole\Process $process) | ||
{ | ||
if(!$this->status) | ||
{ | ||
return; | ||
} | ||
if(null === $this->defaultPath) | ||
{ | ||
$this->defaultPath = [ | ||
Imi::getNamespacePath(App::getNamespace()), | ||
]; | ||
} | ||
go(function(){ | ||
$monitor = BeanFactory::newInstance($this->monitorClass, array_merge($this->defaultPath, $this->includePaths), $this->excludePaths); | ||
$reloadCmd = 'php ' . $_SERVER['argv'][0] . ' server/reload'; | ||
$time = 0; | ||
while(true) | ||
{ | ||
// 检测间隔延时 | ||
sleep(min(max($this->timespan - (microtime(true) - $time), $this->timespan), $this->timespan)); | ||
$time = microtime(true); | ||
// 检查文件是否有修改 | ||
if($monitor->isChanged()) | ||
{ | ||
// 执行重新加载 | ||
Coroutine::exec($reloadCmd); | ||
} | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
namespace Imi\HotUpdate\Monitor; | ||
|
||
abstract class BaseMonitor implements IMonitor | ||
{ | ||
/** | ||
* 包含的路径 | ||
* @var array | ||
*/ | ||
protected $includePaths; | ||
|
||
/** | ||
* 排除的路径 | ||
* @var array | ||
*/ | ||
protected $excludePaths; | ||
|
||
/** | ||
* 构造方法 | ||
* @param array $includePaths 包含的路径 | ||
* @param array $excludePaths 排除的路径 | ||
*/ | ||
public function __construct(array $includePaths, array $excludePaths = []) | ||
{ | ||
$this->includePaths = $includePaths; | ||
$this->excludePaths = $excludePaths; | ||
$this->init(); | ||
} | ||
|
||
/** | ||
* 初始化 | ||
* @return void | ||
*/ | ||
abstract protected function init(); | ||
} |
Oops, something went wrong.