thinkphp5中使用workerman
生活随笔
收集整理的这篇文章主要介绍了
thinkphp5中使用workerman
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
1、composer安装tp5的swoole插件
composer require topthink/think-worker2、WorkerController控制器
namespace app\index\controller;use think\worker\Server; use Workerman\Connection\TcpConnection;class WorkerController extends Server {protected $socket = 'http://0.0.0.0:2345';protected $processes = 1;/*** @param TcpConnection $connection* @param $data*/function onMessage($connection, $data) {$connection->send("<h1>Hello Swoole. #".rand(1000, 9999)."</h1>");} }3、启动文件startWorker.php
define('APP_PATH', __DIR__ . '/../application/');define('BIND_MODULE','index/Worker');require __DIR__ . '/../thinkphp/start.php';4、启动workerman服务
php startWorker.php start php startWorker.php start -d5、浏览器访问
http://127.0.0.1:2345/6、ab压测
ab -c100 -n10000 -k http://127.0.0.1:2345/
转载于:https://www.cnblogs.com/lobtao/articles/7106595.html
总结
以上是生活随笔为你收集整理的thinkphp5中使用workerman的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: Windows虚拟机忘记操作系统密码
- 下一篇: php获取当前时间戳方法