-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
优化:AppContexts::APP_PATH 现在必然可以获取到值 更新文档
- Loading branch information
Showing
1 changed file
with
44 additions
and
44 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Imi\Fpm\Server\Cli; | ||
|
||
use Imi\App; | ||
use Imi\Cli\Annotation\Command; | ||
use Imi\Cli\Annotation\CommandAction; | ||
use Imi\Cli\Annotation\Option; | ||
use Imi\Cli\ArgType; | ||
use Imi\Cli\Contract\BaseCommand; | ||
use Imi\Util\File; | ||
use Imi\Util\Imi; | ||
|
||
/** | ||
* @Command("fpm") | ||
*/ | ||
class Server extends BaseCommand | ||
{ | ||
/** | ||
* 启动 php 内置服务器. | ||
* | ||
* @CommandAction(name="start") | ||
* @Option(name="host", type=ArgType::STRING, default="0.0.0.0", comments="主机名") | ||
* @Option(name="port", type=ArgType::INT, default=8080, comments="端口") | ||
*/ | ||
public function start(string $host, int $port): void | ||
{ | ||
$cmd = '"' . \PHP_BINARY . '" -S ' . $host . ':' . $port . ' -t "' . File::path(Imi::getNamespacePath(App::getNamespace()), 'public') . '"'; | ||
$descriptorspec = [ | ||
['pipe', 'r'], // 标准输入,子进程从此管道中读取数据 | ||
['pipe', 'w'], // 标准输出,子进程向此管道中写入数据 | ||
]; | ||
$p = proc_open(\Imi\cmd($cmd), $descriptorspec, $pipes, null, null, [ | ||
'bypass_shell' => true, | ||
]); | ||
while ($tmp = fgets($pipes[1])) | ||
{ | ||
echo $tmp; | ||
} | ||
proc_close($p); | ||
} | ||
} | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Imi\Fpm\Server\Cli; | ||
|
||
use Imi\App; | ||
use Imi\AppContexts; | ||
use Imi\Cli\Annotation\Command; | ||
use Imi\Cli\Annotation\CommandAction; | ||
use Imi\Cli\Annotation\Option; | ||
use Imi\Cli\ArgType; | ||
use Imi\Cli\Contract\BaseCommand; | ||
use Imi\Util\File; | ||
|
||
/** | ||
* @Command("fpm") | ||
*/ | ||
class Server extends BaseCommand | ||
{ | ||
/** | ||
* 启动 php 内置服务器. | ||
* | ||
* @CommandAction(name="start") | ||
* @Option(name="host", type=ArgType::STRING, default="0.0.0.0", comments="主机名") | ||
* @Option(name="port", type=ArgType::INT, default=8080, comments="端口") | ||
*/ | ||
public function start(string $host, int $port): void | ||
{ | ||
$cmd = '"' . \PHP_BINARY . '" -S ' . $host . ':' . $port . ' -t "' . File::path(App::get(AppContexts::APP_PATH), 'public') . '"'; | ||
$descriptorspec = [ | ||
['pipe', 'r'], // 标准输入,子进程从此管道中读取数据 | ||
['pipe', 'w'], // 标准输出,子进程向此管道中写入数据 | ||
]; | ||
$p = proc_open(\Imi\cmd($cmd), $descriptorspec, $pipes, null, null, [ | ||
'bypass_shell' => true, | ||
]); | ||
while ($tmp = fgets($pipes[1])) | ||
{ | ||
echo $tmp; | ||
} | ||
proc_close($p); | ||
} | ||
} |