次のチュートリアル コラムでは、thinkphp5.1/5.0 のスケジュールされたタスクの実装手順を詳しく説明します。困っている友人の役に立てば幸いです。 私が主に行っているのは、従業員の誕生日にテキスト メッセージを送信する機能です。スクリプトを 1 日に 1 回実行します。
最初のステップ:
a.App /module/b の下にコマンド フォルダーを作成します。管理モジュールで作成し、コマンド フォルダーの下に SendMessage.php ファイルを作成しました (具体的な名前は、に従って自分で決定します)あなたのニーズ)
c. 次のコードを SendMessage.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | <?php
namespace app\admin\command;
use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\Db;
use think\Log;
class SendMessage extends Command
{
protected function configure(){
$this ->setName('SendMessage')->setDescription( "计划任务 SendMessage" );
}
protected function execute(Input $input , Output $output ){
$output ->writeln(' Date Crontab job start...');
$this ->birthday();
$output ->writeln(' Date Crontab job end ...');
}
public function birthday()
{
echo '这里写你要实现的逻辑代码';
}
}
|
ログイン後にコピー
にコピーします。 ステップ 2:
1 | return ['app\admin\command\SendMessage'];
|
ログイン後にコピー
をAPP/command.php
ステップ 3: crontab のスケジュールされたタスクを設定する
#crontab -l //スケジュールされたタスクのリスト
crontab -e //追加するために編集
-
#crontab -r //削除
-
テストを容易にするために、まず 1 分ごとに実行するように設定し、ログ /www/wwwroot/tool/runtime/message/2019.log## を記録します。
## */1 * * * * php /www/wwwroot/tool/think SendMessage>>/www/wwwroot/tool/runtime/message/2019.log 2>&1
##//スクリプトが正常かどうかを監視します
- ##tail -f /www/wwwroot /tool/runtime/message/2019.log
以上がthinkphp5.1/5.0のスケジュールされたタスクの実装手順の詳細な説明の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。