PHP code example of jose-chan / laravel-database-pool

1. Go to this page and download the library: Download jose-chan/laravel-database-pool library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jose-chan / laravel-database-pool example snippets



[
    //……省略

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

];


 
[
    // …… 省略
    '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,
    ]
    // …… 省略
];



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;
        });
    }
}