swoft获取cookie和设置cookie
文档中没有介绍但经过分析,用法如下 获取12request()->cookie()request()->cookie("cookiename") 设置12use Swoft\Http\Message\Cookie\Cookie;$response->withCookie(new Cookie($key, $value, $expire, $path, $domain, $secure, $httponly)); 补充所有的方法封装在以下文件中swoft\http-message\src\Server\Request.phpswoft\http-message\src\Server\Concerns\InteractsWithInput.php 12Swoft\Http\Message\Server\RequestSwoft\Http\Message\Server\Concerns\InteractsWithInput
swoft 中间件 传递数据 request
经过查看源码 1request() 方法会获取当前请求上下文,并在请求结束时销毁,所以可以安全使用他传递数据例如中间件获取用户信息结束后可以 123$req = request();$req->user = $udata;$req->openid = $openid;
swoft 支持 OPTIONS 请求
如果路由中不明确设置,swoft默认只使用了post get请求只要在控制器中明确声明OPTIONS请求即可
swoft 中间件 基本使用
swoft中间件在请求到达控制器之前拦截请求,主要有两种写法 1. 不合法请求12// 直接返回response对象return response() 2. 合法请求12$response = $handler->handle($request);return $response;
easywechat4 开放平台 第三方平台 调用 公众号 jssdk 接口
从微信官方文档中,我们可以知道做这个事情需要一个authorizer_access_token,获取这个需要三个参数component_appid authorizer_appid authorizer_refresh_token默认情况下,你从sdk里传1个appid参数就好了,但是这还不够实际上,sdk没有维护authorizer_refresh_token,这个参数是在用户同意授权时,一起发给我们的,我们需要自己维护,并在调用时传到sdk大致上形如: 12$refresh = (new Component)->getRefreshToken($appid);$app = $open->officialAccount($appid, $refresh);
swoft 获取 容器 swoole_http_server 进程worker_id
获取容器123$con = Swoft\Bean\BeanFactory::getContainer();$app = $con->getBeanNames();return var_export($app,true); 通过BeanFactory类可以操作所有的bean通过以上方法可以获取所有的bean名 获取swool_http_server1234$http = Swoft\App::$server;$server = $http->getServer();$pid = $server->worker_pid;return var_export($pid, true);
windows 安装 wsl 跑 swoole swoft
打开wsl控制面板打开linux子系统 安装子系统在cmd里执行bash或者wsl即可,cmd提示需要安装,可以去商店安装,如果把删除了可以执行 1lxrun /install /y 他会自己下载 安装目录1C:\Users\YourName\AppData\Local\lxss\ 安装swoole从官网下载swoole的二进制包,然后执行加压 1tar -Jxf swoole-4.3.0.tar.xz 运行swoft使用完整的目录即可 1/home/bin/php /mnt/c/php/www/swoft/bin/swoft start
swoole 协程异步 带来的性能提升 压力测试
均访问同一cdn数据,模拟访问远程接口的情况 协程异步2009qps同步阻塞432qps协程压测12345678910111213141516171819202122232425262728Concurrency Level: 200Time taken for tests: 0.498 secondsComplete requests: 1000Failed requests: 0Total transferred: 209000 bytesHTML transferred: 19000 bytesRequests per second: 2009.49 [#/sec] (mean)Time per request: 99.528 [ms] (mean)Time per request: 0.498 [ms] (mean, across all concurrent requests)Transfer rate: 410.14 [Kbytes/sec] receive...
thinkphp beego swoft yaf 性能测试 压力测试 php go swoole 速度对比 helloworld
1ab -n 10000 -c 200 测试机为腾讯云1核1G普通云硬盘,如果用ssd的话php成绩会有所提升 输出内容为时间戳 beego swoft的性能都强的不得了,在同一级别,裸跑性能都逼近nginx处理静态文件nginx转发损耗很大,由于nginx转发会导致thinkphp,swoft,beego的性能几乎一样。所以有可能的话还是不要在这些框架外套个nginx了swoft+nginx:内存无波动,CPU占用81%swoft无nginx:内存无波动,CPU占用34% thinkphp+nginx41212345678910111213141516171819202122232425262728Concurrency Level: 200Time taken for tests: 24.256 secondsComplete requests: 10000Failed requests: 0Total transferred: 1940000 bytesHTML transferred: 190000 by...
swoft 开发的坑 路由不生效
自动重载代码失效根据实测,修改文件必须手动重启swoft,自动重载根本没有卵用