-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from makise-co/feature/pool
Connection pooling
Showing
41 changed files
with
2,039 additions
and
385 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
/** | ||
* This file is part of the Makise-Co Postgres Client | ||
* World line: 0.571024a | ||
* | ||
* (c) Dmitry K. <[email protected]> | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
require dirname(__DIR__) . '/../vendor/autoload.php'; | ||
|
||
use MakiseCo\Postgres\Connection; | ||
use MakiseCo\Postgres\ConnectionConfigBuilder; | ||
use MakiseCo\Postgres\ResultSet; | ||
|
||
use function Swoole\Coroutine\run; | ||
|
||
run( | ||
static function () { | ||
$config = (new ConnectionConfigBuilder()) | ||
->withHost('127.0.0.1') | ||
->withPort(5432) | ||
->withUser('makise') | ||
->withPassword('el-psy-congroo') | ||
->withDatabase('makise') | ||
->build(); | ||
|
||
$connection = new Connection($config); | ||
$connection->connect(); | ||
|
||
/** @var ResultSet $result */ | ||
$result = $connection->query('SHOW ALL'); | ||
|
||
while ($row = $result->fetchAssoc()) { | ||
printf("%-35s = %s (%s)\n", $row['name'], $row['setting'], $row['description']); | ||
} | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
/** | ||
* This file is part of the Makise-Co Postgres Client | ||
* World line: 0.571024a | ||
* | ||
* (c) Dmitry K. <[email protected]> | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
require \dirname(__DIR__) . '/../vendor/autoload.php'; | ||
|
||
use MakiseCo\Postgres\Connection; | ||
use MakiseCo\Postgres\ConnectionConfigBuilder; | ||
use MakiseCo\Postgres\Notification; | ||
use Swoole\Timer; | ||
|
||
use function Swoole\Coroutine\run; | ||
|
||
run( | ||
static function () { | ||
$config = (new ConnectionConfigBuilder()) | ||
->withHost('127.0.0.1') | ||
->withPort(5432) | ||
->withUser('makise') | ||
->withPassword('el-psy-congroo') | ||
->withDatabase('makise') | ||
->build(); | ||
|
||
$connection = new Connection($config); | ||
$connection->connect(); | ||
|
||
$channel = "test"; | ||
|
||
$connection->listen( | ||
$channel, | ||
static function (Notification $notification) { | ||
printf( | ||
"Received notification from PID %d on channel '%s' with payload: %s\n", | ||
$notification->pid, | ||
$notification->channel, | ||
$notification->payload | ||
); | ||
} | ||
); | ||
|
||
printf("Listening on channel '%s'\n", $channel); | ||
|
||
Timer::after( | ||
3000, | ||
function () use ($connection, $channel) { // Unlisten in 3 seconds. | ||
printf("Unlistening from channel '%s'\n", $channel); | ||
$connection->unlisten($channel); | ||
} | ||
); | ||
|
||
Timer::after( | ||
1000, | ||
function () use ($connection, $channel) { | ||
$connection->notify($channel, "Data 1"); // Send first notification. | ||
} | ||
); | ||
|
||
Timer::after( | ||
2000, | ||
function () use ($connection, $channel) { | ||
$connection->notify($channel, "Data 2"); // Send second notification. | ||
} | ||
); | ||
|
||
print_r("[+] Done\n"); | ||
} | ||
); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
/** | ||
* This file is part of the Makise-Co Postgres Client | ||
* World line: 0.571024a | ||
* | ||
* (c) Dmitry K. <[email protected]> | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
require \dirname(__DIR__) . '/../vendor/autoload.php'; | ||
|
||
use MakiseCo\Postgres\Connection; | ||
use MakiseCo\Postgres\ConnectionConfigBuilder; | ||
use Swoole\Timer; | ||
|
||
use function Swoole\Coroutine\run; | ||
|
||
run( | ||
static function () { | ||
$config = (new ConnectionConfigBuilder()) | ||
->withHost('127.0.0.1') | ||
->withPort(5432) | ||
->withUser('makise') | ||
->withPassword('el-psy-congroo') | ||
->withDatabase('makise') | ||
->build(); | ||
|
||
$connection = new Connection($config); | ||
$connection->connect(); | ||
|
||
$channel = "test"; | ||
|
||
/* @var \MakiseCo\Postgres\Listener $listener */ | ||
$listener = $connection->listen($channel, null); | ||
|
||
printf("Listening on channel '%s'\n", $channel); | ||
|
||
Timer::after( | ||
3000, | ||
function () use ($listener) { // Unlisten in 3 seconds. | ||
printf("Unlistening from channel '%s'\n", $listener->getChannel()); | ||
$listener->unlisten(); | ||
} | ||
); | ||
|
||
Timer::after( | ||
1000, | ||
function () use ($connection, $channel) { | ||
$connection->notify($channel, "Data 1"); // Send first notification. | ||
} | ||
); | ||
|
||
Timer::after( | ||
2000, | ||
function () use ($connection, $channel) { | ||
$connection->notify($channel, "Data 2"); // Send second notification. | ||
} | ||
); | ||
|
||
while ($notification = $listener->getNotification()) { | ||
printf( | ||
"Received notification from PID %d on channel '%s' with payload: %s\n", | ||
$notification->pid, | ||
$notification->channel, | ||
$notification->payload | ||
); | ||
} | ||
|
||
print_r("[+] Done\n"); | ||
} | ||
); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
/** | ||
* This file is part of the Makise-Co Postgres Client | ||
* World line: 0.571024a | ||
* | ||
* (c) Dmitry K. <[email protected]> | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
require \dirname(__DIR__) . '/../vendor/autoload.php'; | ||
|
||
use MakiseCo\Postgres\Connection; | ||
use MakiseCo\Postgres\ConnectionConfigBuilder; | ||
|
||
use function Swoole\Coroutine\run; | ||
|
||
run( | ||
static function () { | ||
$config = (new ConnectionConfigBuilder()) | ||
->withHost('127.0.0.1') | ||
->withPort(5432) | ||
->withUser('makise') | ||
->withPassword('el-psy-congroo') | ||
->withDatabase('makise') | ||
->build(); | ||
|
||
$connection = new Connection($config); | ||
$connection->connect(); | ||
|
||
$connection->query('DROP TABLE IF EXISTS test'); | ||
|
||
$transaction = $connection->beginTransaction(); | ||
|
||
$transaction->query('CREATE TABLE test (domain VARCHAR(63), tld VARCHAR(63), PRIMARY KEY (domain, tld))'); | ||
|
||
$statement = $transaction->prepare('INSERT INTO test VALUES (?, ?)'); | ||
|
||
$statement->execute(['amphp', 'org']); | ||
$statement->execute(['google', 'com']); | ||
$statement->execute(['github', 'com']); | ||
|
||
/** @var \MakiseCo\Postgres\ResultSet $result */ | ||
$result = $transaction->execute('SELECT * FROM test WHERE tld = :tld', ['tld' => 'com']); | ||
|
||
$format = "%-20s | %-10s\n"; | ||
printf($format, 'TLD', 'Domain'); | ||
while ($row = $result->fetchAssoc()) { | ||
printf($format, $row['domain'], $row['tld']); | ||
} | ||
|
||
$transaction->rollback(); | ||
} | ||
); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.