PHPackages                             lvinkim/swim-console - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [CLI &amp; Console](/categories/cli)
4. /
5. lvinkim/swim-console

ActiveLibrary[CLI &amp; Console](/categories/cli)

lvinkim/swim-console
====================

v0.2.2(7y ago)1861PHP

Since Aug 18Pushed 7y ago1 watchersCompare

[ Source](https://github.com/lvinkim/swim-console)[ Packagist](https://packagist.org/packages/lvinkim/swim-console)[ RSS](/packages/lvinkim-swim-console/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (4)Versions (6)Used By (1)

swim-console
============

[](#swim-console)

使用 swoole 对 symfony console 的守护任务，计划定时任务，定时重复任务

> 版本支持
> php &gt;= 7.1
> swoole &gt;= 1.7.7

### 安装

[](#安装)

```
composer require lvinkim/swim-console
```

### 守护任务

[](#守护任务)

```
require_once dirname(__DIR__) . '/../../vendor/autoload.php';

$debug = false;
$logDir = __DIR__ . '/../var';
$date = date('Y-m-d');

try {

    $daemonJobber = new \Lvinkim\SwimConsole\DaemonJobber($debug);
    $daemonJobber->setDebugLogFile($logDir . "/daemon-job-debug.log." . $date);

    $daemonJobber->add('cmd-first', [
        'command' => \Tests\App\Command\DaemonFirstCommand::class,
        "commandParam" => ["pass-" . rand(100, 999)],
        'sleep' => 2,   // s
        'enabled' => true,
        "output" => $logDir . "/daemon-cmd-first.log." . $date,
    ]);

    $daemonJobber->add('cmd-second', [
        'command' => \Tests\App\Command\DaemonSecondCommand::class,
        'commandOptions' => ["--caller" => "daemon"],
        'depends' => true,
        'enabled' => true,
        "output" => $logDir . "/daemon-cmd-second.log." . $date,
    ]);

    $daemonJobber->run();

} catch (\Throwable $e) {
    null;
}
```

### 计划定时任务

[](#计划定时任务)

```
require dirname(__DIR__) . '/../../vendor/autoload.php';

$debug = false;
$period = 60 * 1000;    // 每隔 60*1000ms (1分钟) 触发一次
$mission = function ($timerId) use ($debug) {

    $logDir = __DIR__ . '/../var';
    $date = date('Y-m-d');

    try {

        $crontabJobber = new \Lvinkim\SwimConsole\CrontabJobber($debug);
        $crontabJobber->setDebugLogFile($logDir . "/crontab-job-debug.log." . $date);

        $crontabJobber->add("cmd-first", [
            "command" => \Tests\App\Command\CrontabFirstCommand::class,
            "schedule" => "* * * * *",
            "enabled" => true,
            "output" => $logDir . "/crontab-cmd-first.log." . $date,
        ]);

        $crontabJobber->add('cmd-second', [
            "command" => \Tests\App\Command\CrontabSecondCommand::class,
            "commandOptions" => ["--caller" => "crontab"],
            "schedule" => '* * * * *',
            "enabled" => true,
            "output" => $logDir . "/crontab-cmd-second.log." . $date,
        ]);

        $crontabJobber->run();

    } catch (\Throwable $e) {
        null;
    }
};

if ($debug) {
    $mission(uniqid());
} else {
    $timer = swoole_timer_tick($period, $mission);
}
```

### 定时重复任务

[](#定时重复任务)

```
require dirname(__DIR__) . '/../../vendor/autoload.php';

$debug = false;
$logDir = __DIR__ . '/../var';
$date = date('Y-m-d');

try {

    $repeatJobber = new Lvinkim\SwimConsole\RepeatJobber($debug);
    $repeatJobber->setDebugLogFile($logDir . "/repeat-job-debug.log." . $date);

    $repeatJobber->add('cmd-first', [
        'command' => \Tests\App\Command\RepeatFirstCommand::class,
        'depends' => true,
        'enabled' => true,
        "output" => $logDir . "/repeat-cmd-first.log." . $date,
    ]);

    $repeatJobber->add('cmd-second', [
        'command' => \Tests\App\Command\RepeatSecondCommand::class,
        'interval' => 8000, // ms
        'enabled' => true,
        "output" => $logDir . "/repeat-cmd-second.log." . $date,
    ]);

    $repeatJobber->run();

} catch (\Error $e) {
    null;
} catch (Exception $e) {
    null;
} finally {
    null;
}
```

### 计划定时系统命令

[](#计划定时系统命令)

```
require dirname(__DIR__) . '/../../vendor/autoload.php';

$debug = false;
$period = 60 * 1000;    // 每隔 60*1000ms (1分钟) 触发一次
$mission = function ($timerId) use ($debug) {

    $console = __DIR__ . '/console.php';
    $logDir = __DIR__ . '/../var';
    $date = date('Y-m-d');

    try {

        $shellJobber = new \Lvinkim\SwimConsole\ShellJobber($debug);
        $shellJobber->setDebugLogFile($logDir . "/shell-crontab-job-debug.log." . $date);

        $shellJobber->add("cmd-first", [
            "command" => "/usr/bin/env php {$console} cmd:shell-crontab:first --caller=shell-crontab",
            "schedule" => "* * * * *",
            "enabled" => true,
            "output" => $logDir . "/shell-crontab-cmd-first.log." . $date,
        ]);

        $shellJobber->add("cmd-second", [
            "command" => "/usr/bin/env php {$console} cmd:shell-crontab:second --caller=shell-crontab",
            "schedule" => "* * * * *",
            "enabled" => true,
            "output" => $logDir . "/shell-crontab-cmd-second.log." . $date,
        ]);

        $shellJobber->run();

    } catch (\Throwable $e) {
        null;
    }
};

if ($debug) {
    $mission(uniqid());
} else {
    $timer = swoole_timer_tick($period, $mission);
}
```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~4 days

Total

5

Last Release

2810d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/01d0ca591c3a6b31fb49935eb9ef6c2556ac5f1d44057d207fd06a5316b45457?d=identicon)[lvinkim](/maintainers/lvinkim)

---

Top Contributors

[![xiyanghui](https://avatars.githubusercontent.com/u/32087026?v=4)](https://github.com/xiyanghui "xiyanghui (8 commits)")

---

Tags

consolecrontabdaemonphp7processshellswooletimer

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/lvinkim-swim-console/health.svg)

```
[![Health](https://phpackages.com/badges/lvinkim-swim-console/health.svg)](https://phpackages.com/packages/lvinkim-swim-console)
```

###  Alternatives

[illuminate/console

The Illuminate Console package.

12944.1M5.1k](/packages/illuminate-console)[crazywhalecc/static-php-cli

Build single static PHP binary, with PHP project together, with popular extensions included.

1.8k13.9k](/packages/crazywhalecc-static-php-cli)[matthiasnoback/symfony-console-form

Use Symfony forms for Console command input

368264.8k8](/packages/matthiasnoback-symfony-console-form)[phpcr/phpcr-shell

Shell for PHPCR

721.3M8](/packages/phpcr-phpcr-shell)[madewithlove/license-checker

CLI tool to verify allowed licenses for composer dependencies

54449.8k21](/packages/madewithlove-license-checker)[shel/neos-terminal

Neos CMS Ui terminal for running Eel expressions and other commands

1441.3k](/packages/shel-neos-terminal)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
