- PHP 手册
- 函数参考
- 数据库扩展
- 针对各数据库系统对应的扩展
- Mongo
- Miscellaneous
- MongoPool
MongoPool::setSize
(PECL mongo >= 1.2.3)
MongoPool::setSize — Set the size for future connection pools
说明
public static MongoPool::setSize ( int$size
) : bool
Sets the max number of connections new pools will be able to create.
参数
-
size
-
The max number of connections future pools will be able to create. Negative numbers mean that the pool will spawn an infinite number of connections.
返回值
Returns the former value of pool size.
更新日志
版本 | 说明 |
---|---|
1.2.11 | Emits E_DEPRECATED when used. |
范例
Example #1 Mongo::setPoolSize() example
If you set the pool size to n and then create n connections, attempting to create an n+1st connection will throw a MongoConnectionException.
<?php
// only allow one connection to a server
MongoPool::setSize(1);
// creates one connection to localhost:27017
$m1 = new Mongo();
// attempt to create a second connection to localhost:27017
// only one connection is allowed, so this will throw an exception
$m2 = new Mongo();
?>
以上例程的输出类似于:
Fatal error: Uncaught exception 'MongoConnectionException' with message 'no more connections in pool' in /path/to/php/script.php:10 Stack trace: #0 /path/to/php/script.php(10): Mongo->__construct() #1 {main} thrown in /path/to/php/script.php on line 10
参见
- MongoPool::getSize() - Get pool size for connection pools
- MongoPool::info() - Returns information about all connection pools
- The connection documentation.
User Contributed Notes
There are no user contributed notes for this page.官方地址:https://www.php.net/manual/en/mongopool.setsize.php