/** * Perform any necessary shutdown tasks. * This should only be invoked as a register_shutdown callback. * * @access private */ function _shutdown() { if (isset($this->_lockSystem)) { /* Bitch about open locks */ $lockIds = $this->_lockSystem->getLockIds(); foreach ($lockIds as $lockId) { if ($this->getDebug()) { $this->debug(sprintf('Lock id %d was left hanging!', $lockId)); } } /* Release all locks and ignore any errors */ $this->_lockSystem->releaseAllLocks(); $this->_lockSystem->releaseQueue(); } /* Roll back any transactions */ if (isset($this->_storage)) { $this->_storage->rollbackTransaction(); } }
/** * Guarantee that we have at least this many more seconds to work * * After this function completes, we will be guaranteed of at least this much more time to work. * * @param int $limit a time interval in seconds, must be greater than 0 */ function guaranteeTimeLimit($limit) { if ($limit <= 0) { $limit = 30; } $now = time(); if (empty($this->_timeLimit) || $this->_timeLimit - $now < $limit) { $this->debug("[{$now}] can't guarantee {$limit} -- extending!"); /* Make sure that we extend at least a minimum of 30 seconds */ $this->_timeLimit = $now + max($limit, 30); set_time_limit($this->_timeLimit - $now); /* * Then make sure our locks stick around. Even though this returns a status code, we * really don't want to make guaranteeTimeLimit() return a status code since we want to * keep it lightweight. So swallow the return code and don't sweat it for now. */ if (isset($this->_lockSystem)) { $this->_lockSystem->refreshLocks($this->_timeLimit); } } }