Join 4,000+ others and never miss out on new tips, tutorials, and more.
4.x is outdated, please check the latest version 22.x
Latest version:
pecl install openswoole-22.1.2
<?php Swoole\Coroutine\PostgreSQL->connect(string $connectionString): bool
Pass in the Postgres connection string used to connect to the server and database.
Returns true
if there were no connection errors and false
when there was a problem. Check the error message.
Establish a postgresql
non-blocking connection within a coroutine context.
The example shows you how to deal with connection errors.
<?php
use Swoole\Coroutine\PostgreSQL;
Co\run(function()
{
$pg = new PostgreSQL();
$conn = $pg->connect("host=127.0.0.1;port=5432;dbname=test;user=postgres;password=***");
var_dump($pg->error, $conn);
});