jose-chan/laravel-database-pool 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

jose-chan/laravel-database-pool

Composer 安装命令:

composer require jose-chan/laravel-database-pool

包简介

laravel database pool

README 文档

README

! 暂时不建议在pgsql、sqlite、sqlsrv环境中使用,因为仅测试过mysql连接

安装

! composer require jose-chan/laravel-database-pool

配置

config/database.php文件中增加pool配置项

<?php
[
    //……省略

    'pool' => [
        "max" => 10, // 配置最大连接数
    ]

];

使用

找到config/app.php文件中的providers配置,将Illuminate\Database\DatabaseServiceProvider::class替换为JoseChan\Laravel\Database\Pool\Provider\PoolDatabaseServiceProvider::class即可

<?php 
[
    // …… 省略
    'providers' => [

        /*
         * Laravel Framework Service Providers...
         */
        Illuminate\Auth\AuthServiceProvider::class,
        Illuminate\Broadcasting\BroadcastServiceProvider::class,
        Illuminate\Bus\BusServiceProvider::class,
        Illuminate\Cache\CacheServiceProvider::class,
        Illuminate\Foundation\Providers\ConsoleSupportServiceProvider::class,
        Illuminate\Cookie\CookieServiceProvider::class,
        //自己实现的数据库相关
        JoseChan\Laravel\Database\Pool\Provider\PoolDatabaseServiceProvider::class,
        // laravel自带的数据库相关注入
//        Illuminate\Database\DatabaseServiceProvider::class,
        Illuminate\Encryption\EncryptionServiceProvider::class,
        Illuminate\Filesystem\FilesystemServiceProvider::class,
        Illuminate\Foundation\Providers\FoundationServiceProvider::class,
        Illuminate\Hashing\HashServiceProvider::class,
        Illuminate\Mail\MailServiceProvider::class,
        Illuminate\Notifications\NotificationServiceProvider::class,
        Illuminate\Pagination\PaginationServiceProvider::class,
        Illuminate\Pipeline\PipelineServiceProvider::class,
        Illuminate\Queue\QueueServiceProvider::class,
        Illuminate\Redis\RedisServiceProvider::class,
        Illuminate\Auth\Passwords\PasswordResetServiceProvider::class,
        Illuminate\Session\SessionServiceProvider::class,
        Illuminate\Translation\TranslationServiceProvider::class,
        Illuminate\Validation\ValidationServiceProvider::class,
        Illuminate\View\ViewServiceProvider::class,
    ]
    // …… 省略
];

代码使用

<?php
class TestController extends \App\Http\Controllers\Controller
{
    public function fetch(\Illuminate\Http\Request $request)
    {

        $coroutine1 = \Swoole\Coroutine::create(function () {
            $c = microtime(true);

            echo "开始查询1\n";
            $orders = \Illuminate\Database\Eloquent\Model::query()->get();
            $d = microtime(true);
            echo "查询1结束", ($d - $c), "\n";
            return $orders;
        });

        $coroutine = \Swoole\Coroutine::create(function () {
            $e = microtime(true);
            echo "开始查询2\n";
            $orders = \Illuminate\Database\Eloquent\Model::query()->get();
            $f = microtime(true);
            echo "查询2结束", ($f - $e), "\n";
            return $orders;
        });
    }
}

其他说明

  • 该组建适用于laravel框架+swoole协程框架中,协程并发多个sql异步请求mysql,提高整体的执行效率,在非协程环境下,该组建将不会创建多个mysql连接

  • 如果线程池中的所有连接都被借光了,则会抛出一个异常

统计信息

  • 总下载量: 9
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-03-10

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固