swoole 协程coroutine
生活随笔
收集整理的這篇文章主要介紹了
swoole 协程coroutine
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
https://wiki.swoole.com/wiki/page/576.html
協程redis 同步代碼實現異步IO的操作
<?php /** * Created by PhpStorm. * User: whitneywang * Date: 2018/6/4 * Time: 16:10 */ $http = new swoole_http_server('0.0.0.0', 9503); $http->on('request', function ($request, $response) { //協程redis 同步代碼實現異步IO的操作 $redis = new Swoole\Coroutine\Redis(); $redis->connect('127.0.0.1', 6379); $value = $redis->get($request->get['a']); $response->header("Content-Type", "text/plain"); $response->end($value); }); $http->start();程序最大運行時間 就是MYSQL和redis最大時間,比如redis1秒,mysql2秒,最終時間是2秒
傳統是1+2=3秒
所以性能提升,那是相當可以
總結
以上是生活随笔為你收集整理的swoole 协程coroutine的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 3.配电箱(柜)在安装时水平误差每米不大
- 下一篇: swoole 总结