thinkphp5中__destruct何时执行?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | <code><?php
namespace app\shop\drive;
class Redis {
public $handler ;
public function __construct(){
$redis = new \Redis();
$redisConf = config( 'cache.redis' );
$redis ->connect( $redisConf [ 'host' ], $redisConf [ 'port' ]);
$redis ->auth( $redisConf [ 'password' ]);
$this ->handler = $redis ;
}
public function __destruct(){
$this ->handler->close();
}
}</code>
|
控制器中
1 2 3 4 5 6 7 8 9 10 11 12 13 | <code> ...
public $redis , $prefix ;
protected function _initialize(){
$this ->initRedis();
var_dump( $this ->redis->info());
}
private function initRedis()
{
$redis = new Redis;
$this ->redis = $redis ->handler;
var_dump( $this ->redis->info());
$this ->prefix = config( 'cache.redis' )[ 'prefix' ];
}</code>
|
1、这是啥原因?
2、有必要手动关闭redis连接吗?