Laravel,PHP 怎么样运用数据库连接池
<h2 style="color: black; text-align: left; margin-bottom: 10px;">数据库连接池</h2>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">数据库连接池负责分配、管理和释放数据库连接,它<span style="color: black;">准许</span>应用程序重复<span style="color: black;">运用</span>一个现有的数据库连接,而不是再重新<span style="color: black;">创立</span>一个;释放空闲时间超过最大空闲时间的数据库连接来避免<span style="color: black;">由于</span><span style="color: black;">无</span>释放数据库连接而<span style="color: black;">导致</span>的数据库连接遗漏。这项技术能<span style="color: black;">显著</span><span style="color: black;">加强</span>对数据库操作的性能。</p>
<h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;">必须</span></h2>PHP 7.0+SWOOLE 2.1+SMProxyLaravelMySQL<h2 style="color: black; text-align: left; margin-bottom: 10px;">1.安装swoole</h2>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">pecl install swoole</p>
<h2 style="color: black; text-align: left; margin-bottom: 10px;">2.安装<a style="color: black;">SMProxy</a></h2>
<h2 style="color: black; text-align: left; margin-bottom: 10px;">(<span style="color: black;">举荐</span>)直接下载最新发行版的 PHAR 文件,解压即用:</h2>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><a style="color: black;"><span style="color: black;">https://</span><span style="color: black;">github.com/louislivi/sm</span><span style="color: black;">proxy/releases/latest</span></a></p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://pic4.zhimg.com/80/v2-4ddde4a9459987f50678a7df9773d62b_720w.webp" style="width: 50%; margin-bottom: 20px;"></div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">下载前两个压缩包中的一个</p>
<h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;">或</span><span style="color: black;">运用</span> Git 切换任意版本:</h2>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">git clone https://github.com/louislivi/smproxy.git</p>composer install --no-dev # <span style="color: black;">倘若</span>你想贡献你的代码,请不要<span style="color: black;">运用</span> --no-dev 参数。
<h2 style="color: black; text-align: left; margin-bottom: 10px;">3.配置数据库连接池</h2>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">假设MySQL数据库账号为root 密码为654321 库名为 test</p>
<h2 style="color: black; text-align: left; margin-bottom: 10px;">编辑SMProxy 的conf/database.json文件</h2>
<div style="color: black; text-align: left; margin-bottom: 10px;">{
"database": {
"account": {
"root": {
"user": "root",//数据库账号
"password": "654321"//数据库<span style="color: black;">暗码</span>
}
},
"serverInfo": {
"server1": {
"write": {//写库
"host": "127.0.0.1",//数据库<span style="color: black;">位置</span>
"port": 3306,
"timeout": 0.5,//连接超时时间
"flag": 0,
"account": "root"
},
"read": {//读库,<span style="color: black;">无</span>可删掉read列 或填写与写库数据一致内容
"host": "127.0.0.1",
"port": 3306,
"timeout": 0.5,
"flag": 0,
"account": "root"
}
},
"databases": {
"test": {
"serverInfo": "server1",
"startConns": "swoole_cpu_num()*10",
"maxSpareConns": "swoole_cpu_num()*10",
"maxSpareExp": 3600,
"maxConns": "swoole_cpu_num()*20",
"charset": "utf-8"
}
}
}
}</div>
<h2 style="color: black; text-align: left; margin-bottom: 10px;">随后配置SMProxy 的账号<span style="color: black;">暗码</span> 在conf/server.json文件</h2>
<div style="color: black; text-align: left; margin-bottom: 10px;">{
"</div>
我完全赞同你的观点,思考很有深度。 谷歌外链发布 http://www.fok120.com/ 回顾过去一年,是艰难的一年;展望未来,是辉煌的一年。 软文发布论坛开幕式圆满成功。 http://www.fok120.com
页:
[1]