Swoft 是一款基于 Swoole 扩展实现的 PHP 微服务协程框架。Swoft 能像 Go 一样,内置协程网络服务器及常用的协程客户端且常驻内存,不依赖传统的 PHP-FPM。有类似 Go 语言的协程操作方式,有类似 Spring Cloud 框架灵活的注解、强大的全局依赖注入容器、完善的服务治理、灵活强大的 AOP、标准的 PSR 规范实现等等。
Swoft 通过长达三年的积累和方向的探索,把 Swoft 打造成 PHP 界的 Spring Cloud, 它是 PHP 高性能框架和微服务治理的最佳选择。
2.0.7
在 2.0.6
上继续扬帆,已在大量的生产业务中使用,得到很多用户的肯定和支持。正式版本我们做了许多改进和优化,拥有了更好的性能。
通过 Composer 安装 swoft/session 组件
composer require swoft/session
Swoft\Http\Session\SessionMiddleware
中间件加入到全局中间件在配置文件 app/bean.php
里:
'httpDispatcher' => [ // Add global http middleware 'middlewares' => [ \Swoft\Http\Session\SessionMiddleware::class, ], ],
默认是基于本地文件驱动,保存在
runtime/sessions
目录
更在驱动只需要配置对应 handler
类,例如配置 Redis
驱动:
'sessionHandler' => [ 'class' => RedisHandler::class, // Config redis pool 'redis' => bean('redis.pool') ],
配置于 app/bean.php
:
/** @see \Swoft\WebSocket\Server\WsMessageDispatcher */ 'wsMsgDispatcher' => [ 'middlewares' => [ \App\WebSocket\Middleware\GlobalWsMiddleware::class ], ],
/** * Class HomeController * * @WsController(middlewares={DemoMiddleware::class}) */ class TestController {}
配置于 app/bean.php
:
/** @see \Swoft\Tcp\Server\TcpDispatcher */ 'tcpDispatcher' => [ 'middlewares' => [ \App\Tcp\Middleware\GlobalTcpMiddleware::class ], ],
/** * Class DemoController * * @TcpController(middlewares={DemoMiddleware::class}) */ class DemoController { // .... }
升级提示:
Swoole\WebSocket\Server::push
第四个参数 $finish
在 swoole 4.4.12
后改为了 int 类型。TcpServerEvent::CONNECT
事件参数保持跟receive, close一致。 $fd, $server
互换位置。修复(Fixed):
ArrayHelper::get
传入key为 integer 时,报参数错误 a44dcadisEnable()
不生效的问题 da8c51e56uniqid()
方法必须将第二个参数设置为 true c7f688fresponse->delCookie()
无法删除浏览器的cookie数据问题 8eb9241JSON
格式小问题a3fc6b9rpc
服务提供者 getList
调用两次问题fd03e71redis cluster
不支持 auth
参数7a678fjson
类型, 不支持 array
6023a9multi
操作没有及时是否连接 e5f698expireAt
, geoRadius
749241crontab
时间戳检测偏差问题 eb08a46更新(Update):
ConsoleEvent::SHOW_HELP_BEFORE
d3f7bc3newFromArray
和 toArray
方法,方便通过第三方存储(redis
)时导出信息和恢复连接 a8b0b7c增强(Enhancement):
destroyAfterFire
在每次事件调度后清理事件中携带的数据 50bf43d3code
返回fd306f4writeFile
新增写失败异常08c4244(文/开源中国)