Class "Swoole\Database\PDOPool" Not Found : OpenSwoole version 22.0.0, PHP 8.1.14
fakharksa opened this issue · comments
- What did you do? If possible, provide a simple script for reproducing the error.
//db_connection_pool.php
<?php
declare(strict_types=1);
include (dirname(__DIR__).'/config/db_config.php');
use Swoole\Coroutine\PostgreSQL;
use Swoole\Database\PDOConfig;
use Swoole\Database\PDOPool;
use Swoole\Runtime;
function create_db_connection_pool() {
return new PDOPool(
(new PDOConfig())
->withDriver('pgsql')
->withHost(POSTGRES_SERVER_HOST)
->withPort(POSTGRES_SERVER_PORT)
// ->withUnixSocket('/tmp/mysql.sock')
->withDbName(POSTGRES_SERVER_DB)
//->withCharset('')
->withUsername(POSTGRES_SERVER_USER)
->withPassword(POSTGRES_SERVER_PWD)
);
}
where constants are defined in db_config.php as:
const POSTGRES_SERVER_HOST = 'localhost';
const POSTGRES_SERVER_PORT = 5432;
const POSTGRES_SERVER_DB = 'swooledb';
const POSTGRES_SERVER_USER = 'postgres';
const POSTGRES_SERVER_PWD = 'passwd123';
From inside my Main Class:
protected $httpService;
protected $conn_pool_swoole;
function __construct($ip, $port, $serverMode) {
$this->httpService = new Server($ip, $port, $serverMode);
$this->setDefault();
$this->bindWorkerEvents();
$this->bindHttpEvent();
}
protected function bindWorkerEvents() {
$init = function ($server, $worker_id) {
require __DIR__.'/bootstrap/db_connection_pool.php';
$this->conn_pool_swoole = create_db_connection_pool();
}
$this->httpService->on('WorkerStart', $init);
}
- What did you expect to see?
No Error
- What did you see instead?
PHP Fatal error: Uncaught Error: Class "Swoole\Database\PDOPool" not found in /var/www/html/swoole-prac/bootstrap/db_connection_pool.php:49
Stack trace:
#0 /var/www/html/swoole-prac/sw_service.php(92): create_db_connection_pool()
#1 [internal function]: sw_service->{closure}()
#2 {main}
thrown in /var/www/html/swoole-prac/bootstrap/db_connection_pool.php on line
- What version of OpenSwoole are you using (show your
php --ri openswoole
)?
openswoole
Open Swoole => enabled
Author => Open Swoole Group <hello@openswoole.com>
Version => 22.0.0
Built => Jan 13 2023 22:50:54
coroutine => enabled with thread context
debug => enabled
trace_log => enabled
epoll => enabled
eventfd => enabled
signalfd => enabled
cpu_affinity => enabled
spinlock => enabled
rwlock => enabled
sockets => enabled
openssl => OpenSSL 3.0.2 15 Mar 2022
dtls => enabled
http2 => enabled
c-ares => 1.18.1
zlib => 1.2.11
mutex_timedlock => enabled
pthread_barrier => enabled
futex => enabled
mysqlnd => enabled
postgresql => enabled
Directive => Local Value => Master Value
openswoole.enable_coroutine => On => On
openswoole.enable_preemptive_scheduler => Off => Off
openswoole.display_errors => On => On
openswoole.unixsock_buffer_size => 8388608 => 8388608
- What is your machine environment used (show your
uname -a
&php -v
&gcc -v
) ?
**uname -a**
Linux fakhar-HP-Laptop 5.17.5-76051705-generic #202204271406~1651504840~20.04~63e51bd-Ubuntu SMP PREEMPT Wed Ma x86_64 x86_64 x86_64 GNU/Linux
**PHP Version:**
PHP 8.1.14 (cli) (built: Jan 6 2023 15:23:18) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.14, Copyright (c) Zend Technologies
with Zend OPcache v8.1.14, Copyright (c), by Zend Technologies
**GCC Version:**
gcc version 11.3.0 (Ubuntu 11.3.0-1ubuntu1~22.04)
@doubaokun
I am trying "pgsql" driver based on your response to the closed issue
You can also try the following OpenSwoole support channels:
- Documentation - Documentation for Open Swoole
- Slack - Slack channel of Open Swoole
- Discord - Discord server of Open Swoole
Please find PDO pool example at:
https://github.com/openswoole/openswoole/blob/master/example/src/Coroutine/MySQLClientPool.php
Postgres client pool example at:
https://github.com/openswoole/openswoole/blob/master/example/src/Coroutine/PostgresClientPool.php