本文基于Laravel Framework 6.17.1版本
(1).创建项目(依赖真多,如此臃肿)
composer create-project --prefer-dist laravel/laravel blog
(2).安装定时任务composer包
composer require think-task/think-task
(3).执行创建命令行处理类文件(自动生成了文件app/Console/Commands/Task.php)
php artisan make:command Task
(4).修改第3步创建的app/Console/Commands/Task.php为以下内容
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class Task extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'task{action=start}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$action = $this->argument('action');
// 初始化EasyTask
$task = new \ThinkTask\Task();
// 设置项目名称
$task->setPrefix('Think');
// 设置后台运行
$task->setDaemon(false);
// 设置日志保存目录
$task->setRunTimePath('./bootstrap/cache/');
// 添加闭包任务,开2个进程5s执行1次访问网址
$task->addFunc(function () {
@file_get_contents('http://xingxinghan.cn/?id=6');
}, 'Curl_1', 5, 3);
// 添加执行tp默认控制器的方法,开1个进程10s执行1次访问网址
//$task->addClass('\app\index\controller\Index', 'index', 'Curl_2', 10, 1);
// 根据命令执行
if ($action == 'start')
{
$task->start();
}
if ($action == 'status')
{
$task->status();
}
if ($action == 'stop')
{
$task->stop();
}
}
}(5).将上面的文件注册一下(修改app/Console/Kernel.php文件)
protected $commands = [ \App\Console\Commands\Task::class ];
(6).执行命令(windows请使用cmd,由于cmd不支持utf8编码,可以在本站搜索关键字“乱码”相关文章处理),:
php artisan task start 启动命令 php artisan task status 查询命令 php artisan task stop 关闭命令
提示:后台执行失败可修改为前台启动查看问题或者查看日志文件,有问题可以在qq群反馈bug
//参数1 文件名 参数2 缩放比例 function _thumb($_filename,$_percent){ ob_clean();...
本篇文章不是讲解如何用.net开发自己的dll然后PHP通过com调用。主要记录PHP官方支持的DOTNET 基本语法如下:$obj = new DOTNET("assembly", "classname")a...
<?php $data=array('a'=>1,'b'=>2,'c'=>3,'d'=>4); extract($data); var_dump($a,$b,$c,$d); ?>在人人商城中捡到的...
md5/sha1+salt方式是目前各大cms常用的加密方式,虽然salt安全,但是各大md5网站也在研究这个方向,那么我们应该选择password_hash动态hash来助力,一种密码有多种hash结果.看代码模拟登陆.<?php //01.注册 $user ='zhang...
【一】.介绍session由于HTTP是无状态的请求,创建一个会话需要保持必须需要身份标识。当用户第一次访问,PHP会为用户创建一个唯一的sessionid,并将sessionid通过cookie发送给浏览器,并在服务器的临时文件创建一个以sessionid为名的文件用来保存这个sessionid保...
<?php //php7+ define('CONFIG', [ 'MYSQL' => '127.0.0.1',  ...