forked from jmuyuyang/co-psf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPool.php
39 lines (34 loc) · 901 Bytes
/
Pool.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
class Pool{
protected static $_pools = array();
public static function init($adapter,$maxPoolSize = 1){
self::$_pools[$adapter] = new \Connection($adapter,$maxPoolSize);
}
public static function get($adapter,$initData){
if(!isset(self::$_pools[$adapter])){
self::init($adapter);
}
return self::$_pools[$adapter]->get($initData);
}
/**
* 释放单个链接进连接池
* @param unknown $adapter
* @param unknown $connection
*/
public static function release($adapter,$connection){
if(isset(self::$_pools[$adapter])){
self::$_pools[$adapter]->put($connection);
}
}
/**
* 释放连接池中所有的链接
*/
public static function releasePool($adapter){
if(isset(self::$_pools[$adapter])){
foreach(self::$_pools[$adapter] as $connection){
$connection->close();
}
unset(self::$_pools[$adapter]);
}
}
}