Skip to content

Commit ef43ea1

Browse files
committed
update something for swoole wrapper
1 parent b178954 commit ef43ea1

File tree

4 files changed

+27
-16
lines changed

4 files changed

+27
-16
lines changed

examples/Commands/CorCommand.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ public static function aliases(): array
3838
*/
3939
protected function execute($input, $output)
4040
{
41-
$output->dump(Helper::isSupportCoroutine(), Helper::inCoroutine());
41+
$output->aList([
42+
'support coroutine?' => Helper::isSupportCoroutine() ? 'Y' : 'N',
43+
'open coroutine running?' => self::isCoroutine() ? 'Y' : 'N',
44+
'running in coroutine?' => Helper::inCoroutine() ? 'Y' : 'N',
45+
], 'some information');
4246
}
43-
}
47+
}

src/Base/AbstractApplication.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ protected function init()
105105
{
106106
$this->meta['_stats'] = [
107107
'startTime' => microtime(1),
108+
'endTime' => 0,
108109
'startMemory' => memory_get_usage(),
110+
'endMemory' => 0,
109111
];
110112

111113
$this->commandName = $this->input->getCommand();
@@ -190,14 +192,6 @@ abstract public function runAction($name, $action, $believable = false, $standAl
190192

191193
protected function afterRun()
192194
{
193-
// display runtime info
194-
if ($this->isProfile()) {
195-
$title = '---------- Runtime Stats(profile=true) ----------';
196-
$stats = $this->meta['_stats'];
197-
$this->meta['_stats'] = FormatUtil::runtime($stats['startTime'], $stats['startMemory'], $stats);
198-
$this->output->write('');
199-
$this->output->aList($this->meta['_stats'], $title);
200-
}
201195
}
202196

203197
/**
@@ -208,6 +202,15 @@ public function stop($code = 0)
208202
// call 'onAppStop' service, if it is registered.
209203
$this->fire(self::ON_STOP_RUN, [$this]);
210204

205+
// display runtime info
206+
if ($this->isProfile()) {
207+
$title = '------ Runtime Stats(use --profile) ------';
208+
$stats = $this->meta['_stats'];
209+
$this->meta['_stats'] = FormatUtil::runtime($stats['startTime'], $stats['startMemory'], $stats);
210+
$this->output->write('');
211+
$this->output->aList($this->meta['_stats'], $title);
212+
}
213+
211214
exit((int)$code);
212215
}
213216

src/Base/AbstractCommand.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,15 @@ public function run(string $command = ''): int
186186
// if enable coroutine
187187
if (self::isCoroutine() && Helper::isSupportCoroutine()) {
188188
$ok = Coroutine::create(function () {
189-
$status = (int)$this->execute($this->input, $this->output);
190-
189+
$this->execute($this->input, $this->output);
191190
$this->afterExecute();
192-
$this->getApp()->stop($status);
191+
// $this->getApp()->stop($status);
193192
});
193+
194+
// if open debug, output a tips
195+
if (!$ok && $this->input->boolOpt('debug')) {
196+
$this->output->warning('The coroutine create failed!');
197+
}
194198
}
195199

196200
// when not enable coroutine OR coroutine create fail.
@@ -539,15 +543,15 @@ public static function setDescription(string $description)
539543
*/
540544
public static function isCoroutine(): bool
541545
{
542-
return self::$coroutine;
546+
return static::$coroutine;
543547
}
544548

545549
/**
546550
* @param bool $coroutine
547551
*/
548552
public static function setCoroutine($coroutine)
549553
{
550-
self::$coroutine = (bool)$coroutine;
554+
static::$coroutine = (bool)$coroutine;
551555
}
552556

553557
/**

src/Utils/FormatUtil.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ public static function runtime($startTime, $startMem, array $info = []): array
205205
$info['endMemory'] = memory_get_usage();
206206

207207
// 计算运行时间
208-
$info['runtime'] = number_format(($info['endTime'] - $startTime) * 1000, 3) . ' Ms';
208+
$info['runtime'] = number_format(($info['endTime'] - $startTime) * 1000, 3) . ' ms';
209209

210210
if ($startMem) {
211211
$startMem = array_sum(explode(' ', $startMem));

0 commit comments

Comments
 (0)