zoukankan      html  css  js  c++  java
  • lavavel 定时任务 (command的第二个参数)

    之前好像没有写过,记录一下

    $schedule->command()方法

    第一个参数不用说,可以传纯字符串或者类::class,不过第二个参数确很少人提到

    /**
         * Add a new Artisan command event to the schedule.
         *
         * @param  string  $command
         * @param  array  $parameters
         * @return IlluminateConsoleSchedulingEvent
         */
        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");
    

      

  • 相关阅读:
    功能测试--电梯测试项
    进程
    基于UDP协议的socket编程
    自定义报头解决粘包问题
    基于TCP协议的socket编程
    python3 中encode 和decode的使用方法。
    反射---hasattr、getattr、setattr、delattr
    摘要算法---hashlib模块下MD5和SHA的使用
    日志模块---logging
    staticmethod、classmethod的使用
  • 原文地址:https://www.cnblogs.com/cxscode/p/11365690.html
Copyright © 2011-2022 走看看