lavavel 定时任务 (command的第二个参数)
参数 任务 定时 Command 第二个
2023-09-11 14:16:35 时间
之前好像没有写过,记录一下
$schedule->command()方法
第一个参数不用说,可以传纯字符串或者类::class,不过第二个参数确很少人提到
/** * Add a new Artisan command event to the schedule. * * @param string $command * @param array $parameters * @return \Illuminate\Console\Scheduling\Event */ public function command($command, array $parameters = []) { if (class_exists($command)) { $command = Container::getInstance()->make($command)->getName(); } return $this->exec( Application::formatCommandString($command), $parameters ); }
如上第二个参数是数组,看了源码是拼接在命令后面,如果你传二维数组,它也是只会解析排列在命令后面,
/** * Compile parameters for a command. * * @param array $parameters * @return string */ protected function compileParameters(array $parameters) { return collect($parameters)->map(function ($value, $key) { if (is_array($value)) { $value = collect($value)->map(function ($value) { return ProcessUtils::escapeArgument($value); })->implode(' '); } elseif (! is_numeric($value) && ! preg_match('/^(-.$|--.*)/i', $value)) { $value = ProcessUtils::escapeArgument($value); } return is_numeric($key) ? $value : "{$key}={$value}"; })->implode(' '); }
具体是这个方法
传入 [‘a’, 'b'] 解析完 'a' 'b' 传入 [[‘a’, 'b'], 'c'] 解析完 'a' 'b' 'c'
也可以在方法里触发定时任务
Artisan::call("order:log");
相关文章
- js中页面跳转(href)中文参数传输方式
- PHP中$_SERVER参数用法总结
- Spring Boot + RabbitMQ 配置参数解释
- LoadRunner参数化详解
- 深入理解mybatis参数
- python args kwargs 传递参数的区别
- python命令行获取参数
- MySQL优化详解(三)——MySQL慢查询与内参数优化
- Go gin参数绑定
- Go Gin框架使用模板:传入参数(页面显示参数)
- spark standalone提交任务参数配置
- Go语言的可变(不定长)参数函数
- 类型参数的约束(C# 编程指南)
- 多线程之线程池-当任务渐增时的处理-各个参数的含义- 阿里,美团,京东面试题目
- Atitit main函数的ast分析 数组参数调用的ast astview解析
- ML之R:回归预测任务之模型训练部分代码案例—单个模型推理并输出、各个模型基于单个参数训练调优、选择几个最佳模型再进行交叉训练确保模型稳定性实习代码
- error: no match for ‘operator<‘ (operand types are ‘Interval‘ and ‘Interval‘)(sort函数出错(不能省略第三个参数))
- 函数重载中的参数const问题
- Linux |奇怪的知识---complete命令---你不知道的命令参数补全---kubectl命令的参数补全
- Promise - (五)then方法参数回调函数加入异步微任务队列的时机