手機直播原始碼,每日定時重新整理使用者任務
阿新 • • 發佈:2022-03-30
手機直播原始碼,每日定時重新整理使用者任務實現的相關程式碼
<?php
namespace app\common\command;
use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\Output;
class Task extends Command
{
protected function configure()
{
//設定名稱為task
$this->setName('task')
//增加一個命令引數
->addArgument('action', Argument::OPTIONAL, "action")
->addArgument('force', Argument::OPTIONAL, "force");
}
protected function execute(Input $input, Output $output)
{
//獲取輸入引數
$action = trim($input->getArgument('action'));
$force = trim($input->getArgument('force'));
// 配置任務
$task = new \EasyTask\Task();
$task->setRunTimePath('./runtime/');
$task->setDaemon(true);
$task->addFunc(function () {
$this->monitor();
}, 'request', 100, 1);
// 根據命令執行 每隔100s執行一次monitor函式,只開啟一個程序
if ($action == 'start')
{
$task->start();
}
elseif ($action == 'status')
{
$task->status();
}
elseif ($action == 'stop')
{
$force = ($force == 'force'); //是否強制停止
$task->stop($force);
}
else
{
exit('Command is not exist');
}
}
protected function monitor()
{
///執行相應的函式程式碼 和正常的函式一樣 操作資料庫什麼的
}
}
然後直接執行程式碼即可
開始:
php think task start
檢視狀態:
php think task status
結束
php think task stop
以上就是手機直播原始碼,每日定時重新整理使用者任務實現的相關程式碼, 更多內容歡迎關注之後的文章