sugangqiang 2 éve
szülő
commit
42a968f07c
3 módosított fájl, 81 hozzáadás és 0 törlés
  1. 40 0
      app/admin/controller/Task.php
  2. 39 0
      app/command/Solver.php
  3. 2 0
      config/console.php

+ 40 - 0
app/admin/controller/Task.php

@@ -0,0 +1,40 @@
+<?php
+
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+namespace app\admin\controller;
+
+/**
+ * Description of Task
+ *
+ * @author sgq
+ */
+class Task {
+
+    public function index() {
+        $redis = new \think\cache\driver\Redis();
+        $redis->set("test",1);
+        exit();
+        $redis = new \Redis();
+        $redis->connect("127.0.0.1", 6379);
+        $redis->auth("g2#&beauty.cn&#2g");
+        var_dump($redis->hget("product",2301));
+    }
+
+    public function add() {
+        
+    }
+
+    public function edit() {
+        
+    }
+
+    public function delete() {
+        
+    }
+
+}

+ 39 - 0
app/command/Solver.php

@@ -0,0 +1,39 @@
+<?php
+
+declare (strict_types=1);
+
+namespace app\command;
+
+use think\console\Command;
+use think\console\Input;
+use think\console\input\Argument;
+use think\console\input\Option;
+use think\console\Output;
+use think\facade\Db;
+
+/**
+ * 主要处理短信的命令行程序
+ */
+class Solver extends Command {
+
+    protected function configure() {
+        // 指令配置
+        $this->setName('solver')
+                ->setDescription('the solver command');
+    }
+
+    protected function execute(Input $input, Output $output) {
+        // 指令输出
+        $lockFileName = "task_solver.lock";
+        $lockFile = fopen($lockFileName, "a");
+        if (flock($lockFile, LOCK_EX | LOCK_NB)) {//文件锁(独占)
+            set_time_limit(0);
+            $schedules = Db::table("new_schedule")->select();
+            var_dump($info);
+            flock($lockFile, LOCK_UN);
+        } else {
+            $output->writeln('每分钟执行一次,执行时间超过1分钟下个1分钟跳过等待再下1分钟');
+        }
+    }
+
+}

+ 2 - 0
config/console.php

@@ -1,9 +1,11 @@
 <?php
+
 // +----------------------------------------------------------------------
 // | 控制台配置
 // +----------------------------------------------------------------------
 return [
     // 指令定义
     'commands' => [
+        "Solver" => "app\command\Solver"
     ],
 ];