thinkphp5 定時任務

2021-08-16 05:15:29 字數 733 閱讀 5574

前段時間在研究thinkphp5.0版本做自動任務的時候,碰到了棘手的問題–如何做自動化任務,因為程式開始就需要一直執行,查了很多資料,都說靠php原生的死迴圈來做不靠譜,時間誤差也沒法保證,所以後面採用thinkphp5的command工具和伺服器的定時任務來做:

<?php

namespace

usethink\console\command;

usethink\console\input;

usethink\console\output;

class

test

extends

command

protected

function

execute

(input $input, output $output)

private

function

test

()}

<?php
開啟命令列,執行php think test命令test命令execute方法中執行的方法就會執行

task.bat檔案

d:

cd d:\xampp

\htdocs

\autobet

php think test

ps:這裡設定間隔時常,可以是1分鐘到31天,可選項最低是5分鐘,可以手寫!

ThinkPHP5實現定時任務

namespace usethink console command usethink console input usethink console output class test extends command protected function execute input input,ou...

ThinkPHP實現定時任務

專案服務端框架我選用的是thinkphp,由於策劃案中有需求要定時重新整理指定資料,所以在windows平台我使用微軟的計畫任務呼叫bat指令碼來執行下面的命令來完成 php index.php home cli 即使用php的cli模式呼叫thinkphp的入口檔案,然後再傳入指定控制器完成相應的...

thinkphp6 定時任務

使用命令列形式實現定時任務 一 建立乙個自定義命令類檔案 php think make command hello hello declare strict types 1 namespace use think console command use think console input use...