OpenSwoole Core

Latest version: pecl install openswoole-22.1.2 | composer require openswoole/core:22.1.5

OpenSwoole Core is core library implemented with PHP working together with OpenSwoole runtime. You can install OpenSwoole core with composer require openswoole/core.

The features provided by OpenSwoole core:

  • OpenSwoole PSR (provided within OpenSwoole Core package)
  • Coroutine clients for MySQLi, PDO, Redis etc
  • Coroutine helper functions such as WaitGroup
  • Generic Coroutine Connection pools for MySQLi, PDO, Redis etc clients

Overview

OpenSwoole Generic Connection pools

Example

<?php
declare(strict_types=1);

use OpenSwoole\Core\Coroutine\Pool\ClientPool;
use OpenSwoole\Core\Coroutine\Client\PDOClientFactory;
use OpenSwoole\Core\Coroutine\Client\PDOConfig;

co::run(function() {
  $pool = new ClientPool(PDOClientFactory::class, new PDOConfig(), 8, true);

  $mysqlClient = $pool->get();
  $mysqlClient->query('SELECT SLEEP(10)')->fetch();

  $pool->put($mysqlClient);
});

Last updated on September 23, 2022