PHP code example of toolkit / pool

1. Go to this page and download the library: Download toolkit/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/ */

    

toolkit / pool example snippets



use Toolkit\Pool\Raw\ResourcePool;

$rpl = new ResourcePool([
    'initSize' => 2,
    'maxSize' => 2,
    'driverOptions' => [

    ],
]);

$rpl->setCreator(function () {
    $obj = new \stdClass();
    $obj->name = 'test';

    return $obj;
})
    ->setDestroyer(function ($obj) {
    echo "call resource destroyer.\n";
});

var_dump($rpl);

$obj1 = $rpl->get();
$obj2 = $rpl->get();
$obj3 = $rpl->get();

var_dump($obj1, $obj2, $obj3,$rpl);

$rpl->put($obj1);
$rpl->put($obj2);

var_dump($rpl);

$rpl->call(function ($obj) {
   echo " $obj->name\n";
});

var_dump($rpl);

git clone https://git.oschina.net/inhere/php-resource-pool.git // git@osc
git clone https://github.com/inhere/php-resource-pool.git // github