PHP code example of xiaosongshu / fasterphpweb
1. Go to this page and download the library: Download xiaosongshu/fasterphpweb library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
xiaosongshu / fasterphpweb example snippets
# 请在config/server.php 当中配置项目的端口和进程数
return [
//监听端口
'num'=>4,//启动进程数,建议不要超过CPU核数的两倍,windows无效
'port'=>8000,//http监听端口
];
# 注意命名空间
/** 这里表示admin模块 */
namespace App\Controller\Admin;
use APP\Facade\Cache;
use APP\Facade\User;
/**
* @purpose 类名 这里表示index控制器
* @author 作者名称
* @date 2023年4月27日16:05:11
* @note 注意事项
*/
class Index
{
/**
* @method get|post 本项目没有提供强制路由,自动根据模块名/控制器名/方法名 解析
*
*/
public function index()
{
return '/admin/index/index';
}
}
/**
* request以及模板渲染演示
* @param Request $request
* @return array|false|string|string[]
*/
public function database(Request $request)
{
/** 获取var参数 */
$var = $request->get('var');
$name = $request->post('name');
$all = $request->all();
/** 调用数据库 */
$data = User::where('username', '=', 'test')->first();
/** 读取配置 */
$app_name = config('app')['app_name'];
/** 模板渲染 参数传递 */
return view('index/database', ['var' => $var, 'str' => date('Y-m-d H:i:s'), 'user' => json_encode($data), 'app_name' => $app_name]);
}
/** 获取所有get参数 */
$data = $request->get();
/** 获取指定键名参数 */
$name = $request->get('name','tom');
/** 获取所有post请求参数 */
$data = $request->post();
/** 获取指定键名参数 */
$name = $request->post('name','tom');
$data = $request->all();
$post = $request->rawBody();
/** 获取所有的header */
$request->header();
/** 获取指定的header参数host */
$request->header('host');
$request->queryString()
/** 获取cookie */
$request->cookie('username');
/** 获取cookie 并设置默认值 */
$request->cookie('username', 'zhangsan');
return \response()->cookie('zhangsan','tom');
return view('index/database', ['var' => $var, 'str' => date('Y-m-d H:i:s'), 'user' => json_encode($data), 'app_name' => $app_name]);
return response(['status'=>200,'msg'=>'ok','data'=>$data]);
/** 会覆盖response里面的数据 */
return response()->withBody('返回的数据');
return redirect('/admin/user/list');
/** 直接下载 */
return response()->file(public_path().'/favicon.ico');
/** 设置别名 */
return response()->download(public_path().'/favicon.ico','demo.ico');
return \response(['status'=>200,'msg'=>'ok','data'=>$data],200,['Content-Type'=>'application/json']);
return \response(['status'=>200,'msg'=>'ok','data'=>$data])->header('Content-Type','application/json');
return \response(['status'=>200,'msg'=>'ok','data'=>$data])->withHeader('Content-Type','application/json');
return \response(['status'=>200,'msg'=>'ok','data'=>$data])->withHeaders(['Content-Type'=>'application/json']);
return response([],200);
return response([])->withStatus(200);
# 在config/database.php 当中配置
return [
/** 默认连接方式 */
'default'=>'mysql',
/** mysql配置 */
'mysql'=>[
'host'=>'192.168.4.105',
'username'=>'root',
'passwd'=>'root',
'dbname'=>'go_gin_chat',
'port'=>'3306'
],
//todo 其他类型请自己去实现
];
/** 命名空间 */
namespace App\Model;
/** 引入需要继承的模型基类 */
use Root\Model;
/** 定义模型名称 并继承模型基类 */
class Book extends Model
{
/** @var string $table 建议指定表名,否则系统根据模型名推断表名,可能会不准确 */
public $table = 'messages';
}
/** 测试数据库 */
public function query()
{
/** 第1种方法:使用门面类调用模型,需要自己创建门面类 */
$messages = Fbook::where('id', '=', 3)->first();
/** 第2种方法:直接静态化调用 */
$next = Book::where('id','=',1)->first();
return ['status' => 1, 'data' => $messages, 'msg' => 'success','book'=>$book];
}
use App\Model\Admin;
/** 开启事务 */
$transAction = Admin::startTransaction();
try {
/** 如果查询报错,那么写入就会失败 */
$query = Admin::where('id','=',1398)->first();
var_dump($query);
Admin::insert([
'phone'=>'125896325',
'nickname'=>'tom',
'password'=>md5(time())
]);
/** 提交事务 */
$transAction->commit();
}catch (\Exception $exception){
/** 发生了异常,事务回滚 */
$transAction->rollback();
/** 打印报错信息 */
var_dump($exception->getMessage());
}
# 请在config/redis.php 当中配置
return [
/** redis队列开关 */
'enable'=>false,
/** redis连接基本配置 */
//'host' => 'redis',
'host' => '192.168.4.105',
'password' => '',
'port' => '6379',
'database' => 0,
];
/** 测试缓存 */
public function cache()
{
/** 第1种方法,直接静态方法调用 */
Cache::set('happy','new year');
return ['code' => 200, 'msg' => 'ok','静态调用'=>Cache::get('happy')];
}
# config/route.php
return [
/** 首页 */
['GET', '/', [App\Controller\Index\Index::class, 'index']],
/** 路由测试 */
['GET', '/index/demo/index', [\App\Controller\Admin\Index::class, 'index']],
/** 上传文件 */
['GET', '/upload', [\App\Controller\Admin\Index::class, 'upload']],
/** 保存文件 */
['post', '/store', [\App\Controller\Admin\Index::class, 'store']],
/** 缓存存取 */
['get', '/cache', [\App\Controller\Index\Index::class, 'cache']],
/** 返回json */
['get', '/json', [\App\Controller\Index\Index::class, 'json']],
/** 数据库 */
['get', '/database', [\App\Controller\Index\Index::class, 'database']],
/** 数据库写入 */
['get', '/insert', [\App\Controller\Index\Index::class, 'insert']],
/** base64 文件上传 */
['get', '/base64', [\App\Controller\Index\Index::class, 'upload']],
/** base64 文件保存 */
['post', '/base64_store', [\App\Controller\Index\Index::class, 'store']],
/** 测试redis队列 */
['get', '/queue', [\App\Controller\Index\Index::class, 'queue']],
/** 测试rabbitmq队列 */
['get', '/rabbitmq', [\App\Controller\Index\Index::class, 'rabbitmq']],
/** 文件下载 */
['get', '/download', [\App\Controller\Index\Index::class, 'download']],
/** 测试门面类facade */
['get', '/facade', [\App\Controller\Index\Index::class, 'facade']],
/** 测试es搜索 */
['get', '/es', [\App\Controller\Index\Index::class, 'elasticsearch']],
/** 测试中间件 */
['GET','/middle',[\App\Controller\Index\Index::class,'middle'],[\App\Middleware\MiddlewareA::class,\App\Middleware\MiddlewareB::class]]
];
/**
* 测试注解路由
* @param Request $request
* @return Response
*/
#[RequestMapping(methods:'get',path:'/login')]
public function login(Request $request):Response{
return \response(['I am a RequestMapping !']);
}
/**
* 测试注解路由和中间件
* @param Request $request
* @return Response
*/
#[RequestMapping(methods:'get,post',path:'/chat'),Middlewares(MiddlewareA::class)]
public function chat(Request $request):Response{
return \response('我是用的注解路由');
}
namespace App\Middleware;
use Root\Lib\MiddlewareInterface;
use Root\Request;
use Root\Response;
/**
* @purpose 中间件
* @author administrator
* @time 2023-09-28 05:51:21
*/
class Auth implements MiddlewareInterface
{
public function process(Request $request, callable $next):Response
{
//todo 这里处理你的逻辑
return $next($request);
}
}
/** 测试中间件 */
['GET','/middle',[\App\Controller\Index\Index::class,'middle'],[\App\Middleware\MiddlewareA::class,\App\Middleware\MiddlewareB::class]]
/**
* 测试注解路由和中间件
* @param Request $request
* @return Response
*/
#[RequestMapping(methods:'get,post',path:'/chat'),Middlewares(MiddlewareA::class,Auth::class)]
public function chat(Request $request):Response{
return \response('我是用的注解路由');
}
namespace App\Controller\Index;
use App\Service\HahaService;
use Root\Annotation\Mapping\RequestMapping;
use Root\Request;
use Root\Response;
/**
* @purpose 控制器
* @author administrator
* @time 2023-10-11 07:02:03
*/
class Video
{
/**
* @Inject
* @var HahaService 测试服务注解
*/
public HahaService $hahaService;
/**
* 测试注解
* @param Request $request
* @return Response
*/
#[RequestMapping(methods:'get',path:'/video/inject')]
public function testInject(Request $request):Response{
return \response($this->hahaService->back());
}
}
//第一种方式
/** 使用回调函数投递定时任务 */
$first = Timer::add('5',function ($username){
echo date('Y-m-d H:i:s');
echo $username."\r\n";
},['投递的定时任务'],true);
echo "定时器id:".$first."\r\n";
/** 根据id删除定时器 */
Timer::delete($first);
/** 使用数组投递定时任务 */
Timer::add('5',[\Process\CornTask::class,'say'],['投递的定时任务'],true);
/** 获取所有正在运行的定时任务 */
print_r(Timer::getAll());
/** 清除所有定时器 */
Timer::deleteAll();
//第二种,使用配置文件config/timer.php
return [
/** 定时器 */
'one'=>[
/** 是否开启 */
'enable'=>true,
/** 回调函数,调用静态方法 */
'function'=>[Process\CornTask::class,'handle'],
/** 周期 */
'time'=>3,
/** 是否循环执行 */
'persist'=>true,
],
'two'=>[
'enable'=>false,
/** 调用动态方法 */
'function'=>[Process\CornTask::class,'say'],
'time'=>5,
'persist'=>true,
],
'three'=>[
'enable'=>true,
/** 调用匿名函数 */
'function'=>function(){$time=date('y-m-d H:i:s'); echo "\r\n {$time} 我是随手一敲的匿名函数!\r\n";},
'time'=>5,
'persist'=>true,
]
];
# /config/redis.php
return [
/** 是否提前启动缓存连接 */
'preStart'=>false,
/** redis队列开关 */
'enable'=>true,
/** redis连接基本配置 */
'host' => 'redis',
//'host' => '192.168.4.105',
'password' => 'xT9=123456',
'port' => '6379',
'database' => 0,
];
namespace App\Queue;
use Root\Queue\Queue;
/**
* @purpose redis消费者
* @author administrator
* @time 2023-10-31 03:44:50
*/
class Demo extends Queue
{
public $param=null;
/**
* Test constructor.
* @param array $param 根据业务需求,传递业务参数,必须以一个数组的形式传递
*/
public function __construct(array $param)
{
$this->param=$param;
}
/**
* 消费者
* 具体的业务逻辑必须写在handle里面
*/
public function handle(){
//todo 这里写你的具体的业务逻辑
var_dump($this->param);
}
}
/** 普通队列消息 */
\App\Queue\Demo::dispatch(['name' => 'hanmeimei', 'age' => '58']);
/** 延迟队列消息 ,单位秒(s)*/
\App\Queue\Demo::dispatch(['name' => '李磊', 'age' => '32'], 3);
return [
/** rabbitmq基本连接配置 */
'host'=>'faster-rabbitmq',
'port'=>'5672',
'user'=>'guest',
'pass'=>'guest',
];
namespace App\Rabbitmq;
use Root\Queue\RabbitMQBase;
/**
* @purpose rabbitMq消费者
* @author administrator
* @time 2023-10-31 05:27:48
*/
class DemoConsume extends RabbitMQBase
{
/**
* 自定义队列名称
* @var string
*/
public $queueName ="DemoConsume";
/** @var int $timeOut 普通队列 */
public $timeOut=0;
/**
* 逻辑处理
* @param array $param
* @return void
*/
public function handle(array $param)
{
// TODO: Implement handle() method.
}
/**
* 异常处理
* @param \Exception|\RuntimeException $exception
* @return mixed|void
*/
public function error(\Exception|\RuntimeException $exception)
{
// TODO: Implement error() method.
}
}
# config/rabbitmqProcess.php
return [
/** 队列名称 */
'demoForOne'=>[
/** 消费者名称 */
'handler'=>App\Rabbitmq\Demo::class,
/** 进程数 */
'count'=>2,
/** 是否开启消费者 */
'enable'=>false,
],
/** 队列名称 */
'demoForTwo'=>[
/** 消费者名称 */
'handler'=>App\Rabbitmq\Demo2::class,
/** 进程数 */
'count'=>1,
/** 是否开启消费者 */
'enable'=>true,
],
'DemoConsume'=>[
/** 消费者名称 */
'handler'=>App\Rabbitmq\DemoConsume::class,
/** 进程数 */
'count'=>1,
/** 是否开启消费者 */
'enable'=>true,
]
];
(new DemoConsume())->publish(['status'=>1,'msg'=>'ok']);
use root\ESClient;
/** 测试elasticsearch用法 */
public function search()
{
/** 实例化es客户端 */
$client = new ESClient();
/** 查询节点的所有数据 */
return $client->all('v2_es_user3','_doc');
}
# 其他用法参照 root\ESClient::class的源码,
创建索引:createIndex
创建表结构:createMappings
删除索引:deleteIndex
获取索引详情:getIndex
新增一行数据:create
批量写入数据:insert
根据id批量删除数据:deleteMultipleByIds
根据Id 删除一条记录:deleteById
获取表结构:getMap
根据id查询数据:find
根据某一个关键字搜索:search
使用原生方式查询es的数据:nativeQuerySearch
多个字段并列查询,多个字段同时满足需要查询的值:andSearch
or查询 多字段或者查询:orSearch
根据条件删除数据:deleteByQuery
根据权重查询:searchByRank
获取所有数据:all
添加脚本:addScript
获取脚本:getScript
使用脚本查询:searchByScript
使用脚本更新文档:updateByScript
索引是否存在:IndexExists
根据id更新数据:updateById
/** G方法: */
G(App\Service\DemoService::class)->talk(1);
/** M方法:*/
M(App\Service\DemoService::class)->talk(1);
namespace App\Command;
use Root\Lib\BaseCommand;
/**
* @purpose 用户自定义命令
* @author administrator
* @time 2023-10-10 09:11:34
*/
class Demo extends BaseCommand
{
/** @var string $command 命令触发字段,请替换为你自己的命令,执行:php start.php your:command */
public $command = 'Demo';
/**
* 配置参数
* @return void
*/
public function configure(){
/** 必选参数 */
$this->addArgument('argument','这个是参数argument的描述信息');
/** 可传参数 */
$this->addOption('option','这个是option参数的描述信息');
}
/**
* 清在这里编写你的业务逻辑
* @return void
*/
public function handle()
{
/** 获取必选参数 */
var_dump($this->getOption('argument'));
/** 获取可选参数 */
var_dump($this->getOption('option'));
$this->info("请在这里编写你的业务逻辑");
}
}
namespace App\SqliteModel;
use Root\Lib\SqliteBaseModel;
/**
* @purpose sqlite数据库
* @note 示例
*/
class Talk extends SqliteBaseModel
{
/** 存放目录:请修改为你自己的字段,真实路径为config/sqlite.php里面absolute设置的路径 + $dir ,例如:/usr/src/myapp/fasterphpweb/sqlite/datadir/hello/talk */
public string $dir = 'hello/talk';
/** 表名称:请修改为你自己的表名称 */
public string $table = 'talk';
/** 表字段:请修改为你自己的字段 */
public string $field ='id INTEGER PRIMARY KEY,name varhcar(24),created text(12)';
}
use App\SqliteModel\Talk;
/** 写入数据 */
var_dump(Talk::insert(['name' => 'hello', 'created' => time()]));
/** 更新数据 */
var_dump(Talk::where([['id', '>=', 1]])->update(['name' => 'mm']));
/** 查询1条数据 */
var_dump(Talk::where([['id', '>=', 1]])->select(['name'])->first());
/** 删除数据 */
var_dump(Talk::where([['id', '=', 1]])->delete());
/** 统计 */
var_dump(Talk::where([['id', '>', 1]])->count());
/** 查询多条数据并排序分页 */
$res = Talk::where([['id', '>', 0]]) ->orderBy(['created'=>'asc']) ->page(1, 10) ->get();
$dataId = 'CalculatorService';
$group = 'api';
$serviceName = 'mother';
$namespace = 'public';
$client = new \Xiaosongshu\Nacos\Client('http://127.0.0.1:8848','nacos','nacos');
/** 发布配置 */
print_r($client->publishConfig($dataId, $group, json_encode(['name' => 'fool', 'bar' => 'ha'])));
/** 获取配置 */
print_r($client->getConfig($dataId, $group,'public'));
/** 监听配置 */
print_r($client->listenerConfig($dataId, $group, json_encode(['name' => 'fool', 'bar' => 'ha'])));
/** 删除配置 */
print_r($client->deleteConfig($dataId, $group));
/** 创建服务 */
print_r($client->createService($serviceName, $namespace, json_encode(['name' => 'tom', 'age' => 15])));
/** 创建实例 */
print_r($client->createInstance($serviceName, "192.168.4.110", '9504', $namespace, json_encode(['name' => 'tom', 'age' => 15]), 99, 1, false));
/** 获取服务列表 */
print_r($client->getServiceList($namespace));
/** 服务详情 */
print_r($client->getServiceDetail($serviceName, $namespace));
/** 获取实例列表 */
print_r($client->getInstanceList($serviceName, $namespace));
/** 获取实例详情 */
print_r($client->getInstanceDetail($serviceName, false, '192.168.4.110', '9504'));
/** 更新实例健康状态 */
print_r($client->updateInstanceHealthy($serviceName, $namespace, '192.168.4.110', '9504',false));
/** 发送心跳 */
print_r($client->sendBeat($serviceName, '192.168.4.110', 9504, $namespace, false, 'beat'));
/** 移除实例*/
print_r($client->removeInstance($serviceName, '192.168.4.110', 9504, $namespace, false));
/** 删除服务 */
print_r($client->removeService($serviceName, $namespace));
# config/nacos.php
return [
/** 使用nacos自动管理配置 */
/** 是否开启配置管理 */
'enable' => true,
/** nacos服务器ip */
'host' => '192.168.4.98',
/** nacos服务器端口 */
'port' => 8848,
/** nacos 服务器用户名 */
'username' => 'nacos',
/** nacos服务器密码 */
'password' => 'nacos',
];
return [
/** 默认连接方式 */
'default'=>'mysql',
/** mysql配置 */
'mysql'=>[
/** 是否提前连接MySQL */
'preStart'=>false,
/** mysql基本配置 */
'host'=>'192.168.4.106',
'username'=>'root',
'passwd'=>'root',
'dbname'=>'go_gin_chat',
'port'=>'3306'
],
'mysql2'=>[
'host'=>yaml('mysql.host'),
'port'=>yaml('mysql.port'),
'username'=>yaml('mysql.username'),
'passwd'=>yaml('mysql.password'),
'dbname'=>yaml('mysql.dbname','go_gin_chat'),
]
//todo 其他类型请自己去实现
];
namespace Ws;
use RuntimeException;
use Root\Lib\WsSelectorService;
use Root\Lib\WsEpollService;
/**
* @purpose ws服务
* @author administrator
* @time 2023-09-28 10:47:59
* @note 这是一个websocket服务端示例
*/
class Just extends WsEpollService
{
/** ws 监听ip */
public string $host= '0.0.0.0';
/** 监听端口 */
public int $port = 9501;
public function __construct(){
//todo 编写可能需要的逻辑
}
/**
* 建立连接事件
* @param $socket
* @return mixed|void
*/
public function onConnect($socket)
{
// TODO: Implement onConnect() method.
$allClients = $this->getAllUser();
$clients = [];
foreach ($allClients as $client){
$clients[]=$client->id;
}
$this->sendTo($socket,['type'=>'getAllClients','content'=>$clients,'from'=>'server','to'=>$this->getUserInfoBySocket($socket)->id]);
}
/**
* 消息事件
* @param $socket
* @param $message
* @return mixed|void
*/
public function onMessage($socket, $message)
{
// TODO: Implement onMessage() method.
/** 消息格式 */
# type:[ping,message,getAllClients],content:[string,array,json],to:[uid,all]
$message = json_decode($message,true);
/** 消息类型 */
$type = $message['type']??null;
/** 消息体 */
$content = $message['content']??'';
/** 接收人 */
$sendTo = $message['to']??'all';
/** 处理消息 */
switch ($type){
/** 心跳 */
case 'ping':
$this->sendTo($socket,['type'=>'pong','content'=>'pong','from'=>'sever','to'=>$this->getUserInfoBySocket($socket)->id??0]);
break;
/** 消息 */
case 'message':
if ($sendTo=='all'){
$this->sendToAll(['type'=>'message','content'=>$content,'to'=>'all','from'=>$this->getUserInfoBySocket($socket)->id??0]);
}else{
$to = $this->getUserInfoByUid($sendTo);
$from = $this->getUserInfoBySocket($socket);
if ($to){
$this->sendTo($to->socket,['type'=>'message','content'=>$content,'to'=>$to->id??0,'from'=>$from->id??0]);
}else{
$this->sendTo($socket,['type'=>'message','content'=>'send message fail,the client is off line !','to'=>$from->id??0,'from'=>'server']);
}
}
break;
/** 获取所有的客户端 */
case "getAllClients":
$allClients = $this->getAllUser();
$clients = [];
foreach ($allClients as $client){
$clients[]=$client->id;
}
$this->sendTo($socket,['type'=>'getAllClients','content'=>$clients,'from'=>'server','to'=>$this->getUserInfoBySocket($socket)->id]);
break;
default:
/** 未识别的消息类型 */
$this->sendTo($socket,['type'=>'error','content'=>'wrong message type !','from'=>'server','to'=>$this->getUserInfoBySocket($socket)->id]);
}
}
/**
* 连接断开事件
* @param $socket
* @return mixed|void
*/
public function onClose($socket)
{
// TODO: Implement onClose() method.
}
/**
* 异常事件
* @param $socket
* @param \Exception $exception
* @return mixed|void
*/
public function onError($socket, \Exception $exception)
{
//var_dump($exception->getMessage());
$this->close($socket);
}
}
return [
'ws1'=>[
/** 是否开启 */
'enable'=>false,
/** 服务类 */
'handler'=>\Ws\TestWs::class,
/** 监听ip */
'host'=>'0.0.0.0',
/** 监听端口 */
'port'=>'9502'
],
'ws2'=>[
'enable'=>true,
'handler'=>\Ws\TestWs2::class,
'host'=>'0.0.0.0',
'port'=>'9504'
],
'ws3'=>[
'enable'=>true,
'handler'=>\Ws\Just::class,
'host'=>'0.0.0.0',
'port'=>'9503'
],
];
use Root\Lib\WsClient;
/** 初始化 设置需要连接的ws服务器 */
WsClient::setUp('127.0.0.1',9503);
/** 发送一条数据 */
WsClient::send(['type'=>'ping']);
/** 读取一条数据 */
var_dump(WsClient::get());
/** 设置消息回调函数,负责处理接收到消息后逻辑,若不设置,则自动丢弃消息 */
WsClient::$onMessage = function ($message){
$message = json_decode($message,true);
/** 消息类型 */
$type = $message['type']??null;
/** 消息体 */
$content = $message['content']??'';
/** 接收人 */
$sendTo = $message['to']??'all';
if ($sendTo=='all'){
var_dump("广播的消息",$content);
}else{
var_dump("私聊给我的消息",$content);
}
};
/** 开启客户端监听 */
WsClient::start();
return [
/** 是否开启直播服务,该配置仅后台守护进程模式有效 */
'enable'=>true,
/** rmtp 服务端口 守护进程模式和开发模式均有效 */
'rtmp'=>1935,
/** flv端口 守护进程模式和开发模式均有效 */
'flv'=>18080
];
use Root\Lib\HttpClient;
/** 同步请求 请求百度 */
$response = (HttpClient::request('www.baidu.com', 'GET',['lesson_id'=>201]));
var_dump($response->header());
/** 异步请求 请求百度 */
/** 发送异步请求 */
HttpClient::requestAsync('127.0.0.1:9501', 'GET', ['lesson_id' => 201], [], [], function (Request $message) {
if ($message->rawBuffer()){
var_dump("成功回调方法有数据");
}
}, function (\RuntimeException $exception) {
var_dump($exception->getMessage());
});
/** 发件人 你的邮箱地址 */
$user = '[email protected] ';
/** 发件人授权码 在邮箱的设置,账户,smtp里面 */
$password = 'xxxxxxxx';
/** 邮箱服务器地址 */
$url = 'smtp.qq.com:25';
try {
/** 实例化客户端 */
$client = new \Xiaosongshu\Mail\Client();
/** 配置服务器地址 ,发件人信息 */
$client->config($url, $user, $password);
/** 发送邮件 语法:[收件人邮箱] ,邮件主题, 邮件正文,[附件] */
$res = $client->send( ['[email protected] '],'标题', '正文呢',[__DIR__.'/favicon.ico',__DIR__.'/favicon2.ico',]);
print_r($res);
} catch (Exception $exception) {
print_r("发送邮件失败");
print_r($exception->getMessage());
}
bash
开启 php start.php start -d 关闭 php start.php stop
bash
开启 php windows.php 关闭 php windows.php stop
bash
php songshu make:middleware Auth
php start.php make:middleware Auth
bash
php songshu make:queue Demo
bash
php start.php make:rabbitmq DemoConsume
bash
php start.php make:command Demo
bash
php start.php make:sqlite Talk
bash
php songshu make:sqlite Talk
bash
php start.php make:ws Just
bash
php start.php ws:start Ws.Just
bash
# 调试模式
php start.php rtmp start
# 守护模式
php start.php rtmp start -d
# 重启服务(调试模式)
php start.php rtmp restart
# 关闭服务
php start.php rtmp stop
bash
php start.php check:email
bash
php -d phar.readonly=0 songshu.phar start/restart/stop [-d]
bash
php -d phar.readonly=0 songshu make:bin
bash
php snow.php # 雪飘人间 这个是模拟的飘雪的效果,有闪电、云朵和雪花
php flower.php # 万花筒 别被名字唬住了,就是简单的螺旋形流星效果
php three.php # 旋转的立方体 这个和上面的动画不一样,是三维动画,将三维立方体投射到二维平面,生成动画