/** * Check the max lag if necessary * @param ApiBase $module Api module being used * @param array $params Array an array containing the request parameters. * @return bool True on success, false should exit immediately */ protected function checkMaxLag($module, $params) { if ($module->shouldCheckMaxlag() && isset($params['maxlag'])) { // Check for maxlag $maxLag = $params['maxlag']; list($host, $lag) = wfGetLB()->getMaxLag(); if ($lag > $maxLag) { $response = $this->getRequest()->response(); $response->header('Retry-After: ' . max(intval($maxLag), 5)); $response->header('X-Database-Lag: ' . intval($lag)); if ($this->getConfig()->get('ShowHostnames')) { $this->dieUsage("Waiting for {$host}: {$lag} seconds lagged", 'maxlag'); } $this->dieUsage("Waiting for a database server: {$lag} seconds lagged", 'maxlag'); } } return true; }