예제 #1
0
 /**
  * Helper to purge an array of $urls
  * @param array $urls List of URLS to purge from squids
  */
 private function sendPurgeRequest($urls)
 {
     if ($this->hasOption('delay')) {
         $delay = floatval($this->getOption('delay'));
         foreach ($urls as $url) {
             if ($this->hasOption('verbose')) {
                 $this->output($url . "\n");
             }
             $u = new CdnCacheUpdate(array($url));
             $u->doUpdate();
             usleep($delay * 1000000.0);
         }
     } else {
         if ($this->hasOption('verbose')) {
             $this->output(implode("\n", $urls) . "\n");
         }
         $u = new CdnCacheUpdate($urls);
         $u->doUpdate();
     }
 }
예제 #2
0
 public function execute()
 {
     global $wgHTCPRouting;
     if ($this->hasOption('htcp-dest')) {
         $parts = explode(':', $this->getOption('htcp-dest'));
         if (count($parts) < 2) {
             // Add default htcp port
             $parts[] = '4827';
         }
         // Route all HTCP messages to provided host:port
         $wgHTCPRouting = ['' => ['host' => $parts[0], 'port' => $parts[1]]];
         if ($this->hasOption('verbose')) {
             $this->output("HTCP broadcasts to {$parts[0]}:{$parts[1]}\n");
         }
     }
     $dbr = $this->getDB(DB_REPLICA);
     $minTime = $dbr->timestamp($this->getOption('starttime'));
     $maxTime = $dbr->timestamp($this->getOption('endtime'));
     if ($maxTime < $minTime) {
         $this->error("\nERROR: starttime after endtime\n");
         $this->maybeHelp(true);
     }
     $stuckCount = 0;
     // loop breaker
     while (true) {
         // Adjust bach size if we are stuck in a second that had many changes
         $bSize = $this->mBatchSize + $stuckCount * $this->mBatchSize;
         $res = $dbr->select(['page', 'revision'], ['rev_timestamp', 'page_namespace', 'page_title'], ["rev_timestamp > " . $dbr->addQuotes($minTime), "rev_timestamp <= " . $dbr->addQuotes($maxTime), "page_latest = rev_id"], __METHOD__, ['ORDER BY' => 'rev_timestamp', 'LIMIT' => $bSize], ['page' => ['INNER JOIN', 'rev_page=page_id']]);
         if (!$res->numRows()) {
             // nothing more found so we are done
             break;
         }
         // Kludge to not get stuck in loops for batches with the same timestamp
         list($rows, $lastTime) = $this->pageableSortedRows($res, 'rev_timestamp', $bSize);
         if (!count($rows)) {
             ++$stuckCount;
             continue;
         }
         // Reset suck counter
         $stuckCount = 0;
         $this->output("Processing changes from {$minTime} to {$lastTime}.\n");
         // Advance past the last row next time
         $minTime = $lastTime;
         // Create list of URLs from page_namespace + page_title
         $urls = [];
         foreach ($rows as $row) {
             $title = Title::makeTitle($row->page_namespace, $row->page_title);
             $urls[] = $title->getInternalURL();
         }
         if ($this->hasOption('dry-run') || $this->hasOption('verbose')) {
             $this->output(implode("\n", $urls) . "\n");
             if ($this->hasOption('dry-run')) {
                 continue;
             }
         }
         // Send batch of purge requests out to squids
         $squid = new CdnCacheUpdate($urls, count($urls));
         $squid->doUpdate();
         if ($this->hasOption('sleep-per-batch')) {
             // sleep-per-batch is milliseconds, usleep wants micro seconds.
             usleep(1000 * (int) $this->getOption('sleep-per-batch'));
         }
     }
     $this->output("Done!\n");
 }