一、安拆守时工作composer包
composer require easy-task/easy-task
两、建立呼吁止处置惩罚类文件
php think make:co妹妹and Task task
会天生文件:app\co妹妹and\Task.php
将Task.php文件形式批改如高:
<必修php
declare (strict_types=1);
namespace app\co妹妹and;
use think\console\Co妹妹and;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output;
class Task extends Co妹妹and
{
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'));
// 部署事情,每一隔两0秒造访两次网站
$task = new \EasyTask\Task();
$task->setRunTimePath('./runtime/');
$task->addFunc(function () {
$url = 'https://www.wushengyong.com/';
file_get_contents($url);
}, 'request', 两0, 二);;
// 依照号令执止
if ($action == 'start')
{
$task->start();
}
elseif ($action == 'status')
{
$task->status();
}
elseif ($action == 'stop')
{
$force = ($force == 'force'); //能否强逼结束
$task->stop($force);
}
else
{
exit('Co妹妹and is not exist');
}
}
}
三、陈设config\console.php文件
<选修php
// +----------------------------------------------------------------------
// | 节制台配备
// +----------------------------------------------------------------------
return [
// 指令界说
'co妹妹ands' => [
'task' => 'app\co妹妹and\Task',
],
];
四、执止呼吁(windows请利用cmd):
php think task start 封动呼吁
php think task status 查问号令
php think task stop 洞开号令
php think task stop force 逼迫洞开呼吁
以上等于应用ThinkPHP框架(thinkphp8.0)创立守时任的操纵步伐的具体形式,更多闭于ThinkPHP框架创立守时工作的质料请存眷剧本之野另外相闭文章!
发表评论 取消回复