hyperf: 开发时代码热更新
一,安装第三方库
$ composer require hyperf/watcher --dev
二,配置
1,生成配置文件:
$ php bin/hyperf.php vendor:publish hyperf/watcher
[hyperf/watcher] publishes [config] successfully.
文件位置:
项目根目录/.watcher.php
默认代码:
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
use Hyperf\Watcher\Driver\ScanFileDriver;
return [
'driver' => ScanFileDriver::class,
'bin' => PHP_BINARY,
'watch' => [
'dir' => ['app', 'config'],
'file' => ['.env'],
'scan_interval' => 2000,
],
'ext' => ['.php', '.env'],
];
三,应用,测试效果:
$ php bin/hyperf.php server:watch
Generating optimized autoload files
Generated optimized autoload files containing 4700 classes
Start server ...
[INFO] Worker#0 started.
[INFO] HTTP Server listening at 0.0.0.0:9501
[INFO] Worker#1 started.
浙公网安备 33010602011771号