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 |
try{ static $instances; if(!isset($instances)){ $dbLink = new StatDBLink( $this->options['db_host'], $this->options['db_user'], $this->options['db_pwd'] ); $dbo = new StatDbo($dbLink); $dbo->isDebug = $this->isDebug(); $tools = new StatTools($dbo); $ip = new StatIpLocation(__DIR__ . '/QQWry.Dat'); $region = new StatArea(); $instances = new StatLog($tools, $ip, $region); } $this->isDebug() && $this->log(var_export($data, true)); $instances->add($data); } catch(Exception $e){ $this->log($e->getMessage()); $this->logError($e->getMessage()); // 清理资源,在swoole下特别注意,经常unset()不需要的变量 unset($instances); if(isset($dbLink)){ $dbLink->close(); unset($dbLink); } } |
在发生Exception后,static类型的变量instances未被unset