swoft 中间件 传递数据 request
发表于|更新于|php
|浏览量:
经过查看源码
1 | request() |
方法会获取当前请求上下文,并在请求结束时销毁,
所以可以安全使用他传递数据
例如中间件获取用户信息结束后
可以
1 | $req = request(); |
文章作者: developer
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来源 Dev!
相关推荐
2019-03-15
swoft 中间件 基本使用
swoft中间件在请求到达控制器之前拦截请求,主要有两种写法 1. 不合法请求12// 直接返回response对象return response() 2. 合法请求12$response = $handler->handle($request);return $response;
2019-03-04
swoft 开发的坑 路由不生效
自动重载代码失效根据实测,修改文件必须手动重启swoft,自动重载根本没有卵用
2019-03-04
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...
2019-03-17
swoft 控制器参数注入和 从 容器获取的不同点
经过测试控制器参数注入大致上和自己直接new没有区别,被实例化的类中的,注解内容没有起作用 只有通过类似 1BeanFactory::getBean("gameConfig"); 这样获取时候,用注解初始化的值才会有作用 123456789101112131415use Swoft\Bean\Annotation\Bean;use Swoft\Bean\Annotation\Scope;use Swoft\Bean\Annotation\Value;/** * 注入类 * @Bean(name="gameConfig",scope=Scope::SINGLETON) *//** * 注入属性值 * @Value(name="${config.loginkey}", env="${PFILE}") * @var string */public $val;
2019-03-08
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);
2019-03-20
ajax 中 request payload 和 form data 区别
在使用swoft时候发现ajax如果设置header 1xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 后端可以收到如果不设置,默认header是 1Content-Type:text/plain;charset=UTF-8 后端就接受不到参数
公告
This is my Blog