max = 100; $event = Snowflake::app()->getEvent(); $event->on(Event::EVENT_AFTER_REQUEST, [$this, 'destruct']); } /** * @param array $config * @param array $construct * @return mixed * @throws Exception */ public function load(mixed $config, array $construct = []): mixed { if (is_object($config)) { return $config; } return $this->getFromChannel($name = md5($config), [$config, $construct]); } /** * @param string $name * @param mixed $config * @return mixed * @throws ReflectionException * @throws NotFindClassException */ public function createClient(string $name, mixed $config): mixed { return Snowflake::createObject(...$config); } /** * @param string $name * @param $object */ public function release(string $name, mixed $object) { if (!isset($this->_waitRecover[$name])) { $this->_waitRecover[$name] = []; } $this->_waitRecover[$name][] = $object; } public function destruct() { if (empty($this->_waitRecover)) { return; } foreach ($this->_waitRecover as $name => $value) { if (empty($value)) { continue; } foreach ($value as $object) { if (method_exists($object, 'clean')) { $object->clean(); } $this->push($name, $object); } } $this->_waitRecover = []; } }