1. Go to this page and download the library: Download shado/php-resource-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/ */
shado / php-resource-pool example snippets
$factory = function (\Shado\ResourcePool\FactoryController $controller) {
$newConnection = new DbConnection();
$newConnection->onClose($controller->detach(...));
$newConnection->onError($controller->detach(...));
return $newConnection;
};
$pool = new \Shado\ResourcePool\ResourcePool($factory, limit: 10);
$connection = $pool->borrow(); // `$connection` is ready to use :)
try {
// $connection->query(...);
} finally {
$pool->return($connection);
}
$factory = function (\Shado\ResourcePool\FactoryController $controller) {
$newConnection = new DbConnection();
$newConnection->onClose($controller->detach(...));
$newConnection->onError($controller->detach(...));
return $newConnection;
};
$pool = new \Shado\ResourcePool\AsyncResourcePool(
new \Shado\ResourcePool\ResourcePool($factory, limit: 10),
retryingTimeout: null,
retryingDelay: 0.01
);
$connection = $pool->borrow(); // `$connection` is ready to use :)
// ...or you can make use of the Promise:
// $connection = \React\Async\await($pool->borrowAsync());
try {
// $connection->query(...);
} finally {
$pool->return($connection);
}
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.