2004-02-18 02:15:00 +00:00
|
|
|
<?php
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
2012-05-08 12:51:21 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @file
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2004-01-30 16:06:22 +00:00
|
|
|
|
2016-04-23 00:09:14 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2020-01-10 00:00:51 +00:00
|
|
|
use Wikimedia\Assert\Assert;
|
2015-11-30 23:26:45 +00:00
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
2019-09-11 22:00:13 +00:00
|
|
|
* Handles purging the appropriate CDN objects given a list of URLs or Title instances
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @ingroup Cache
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2015-12-09 18:05:59 +00:00
|
|
|
class CdnCacheUpdate implements DeferrableUpdate, MergeableUpdate {
|
2019-03-15 00:23:26 +00:00
|
|
|
/** @var array[] List of (URL, rebound purge delay) tuples */
|
|
|
|
|
private $urlTuples = [];
|
|
|
|
|
/** @var array[] List of (Title, rebound purge delay) tuples */
|
|
|
|
|
private $titleTuples = [];
|
|
|
|
|
|
|
|
|
|
/** @var int Maximum seconds of rebound purge delay (sanity) */
|
|
|
|
|
const MAX_REBOUND_DELAY = 300;
|
2013-10-11 22:41:59 +00:00
|
|
|
|
|
|
|
|
/**
|
2019-03-15 00:23:26 +00:00
|
|
|
* @param string[]|Title[] $targets Collection of URLs/titles to be purged from CDN
|
|
|
|
|
* @param array $options Options map. Supports:
|
|
|
|
|
* - reboundDelay: how many seconds after the first purge to send a rebound purge.
|
|
|
|
|
* No rebound purge will be sent if this is not positive. [Default: 0]
|
2013-10-11 22:41:59 +00:00
|
|
|
*/
|
2019-03-15 00:23:26 +00:00
|
|
|
public function __construct( array $targets, array $options = [] ) {
|
|
|
|
|
$delay = min(
|
|
|
|
|
(int)max( $options['reboundDelay'] ?? 0, 0 ),
|
|
|
|
|
self::MAX_REBOUND_DELAY
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
foreach ( $targets as $target ) {
|
|
|
|
|
if ( $target instanceof Title ) {
|
|
|
|
|
$this->titleTuples[] = [ $target, $delay ];
|
|
|
|
|
} else {
|
|
|
|
|
$this->urlTuples[] = [ $target, $delay ];
|
|
|
|
|
}
|
|
|
|
|
}
|
2004-03-08 09:43:36 +00:00
|
|
|
}
|
2004-01-30 16:06:22 +00:00
|
|
|
|
2015-11-13 06:41:37 +00:00
|
|
|
public function merge( MergeableUpdate $update ) {
|
2019-09-07 14:38:07 +00:00
|
|
|
/** @var self $update */
|
2015-11-13 06:41:37 +00:00
|
|
|
Assert::parameterType( __CLASS__, $update, '$update' );
|
2019-09-07 14:38:07 +00:00
|
|
|
'@phan-var self $update';
|
2015-11-13 06:41:37 +00:00
|
|
|
|
2019-03-15 00:23:26 +00:00
|
|
|
$this->urlTuples = array_merge( $this->urlTuples, $update->urlTuples );
|
|
|
|
|
$this->titleTuples = array_merge( $this->titleTuples, $update->titleTuples );
|
2015-11-13 06:41:37 +00:00
|
|
|
}
|
|
|
|
|
|
2009-02-16 14:26:34 +00:00
|
|
|
/**
|
2015-12-09 18:05:59 +00:00
|
|
|
* Create an update object from an array of Title objects, or a TitleArray object
|
2011-04-25 22:41:54 +00:00
|
|
|
*
|
2017-08-29 16:30:14 +00:00
|
|
|
* @param Traversable|Title[] $titles
|
2019-03-15 00:23:26 +00:00
|
|
|
* @param string[] $urls
|
2015-12-09 18:05:59 +00:00
|
|
|
* @return CdnCacheUpdate
|
2019-03-15 00:23:26 +00:00
|
|
|
* @deprecated Since 1.35 Use HtmlCacheUpdater instead
|
2009-02-16 14:26:34 +00:00
|
|
|
*/
|
2019-03-15 00:23:26 +00:00
|
|
|
public static function newFromTitles( $titles, $urls = [] ) {
|
|
|
|
|
return new CdnCacheUpdate( array_merge( $titles, $urls ) );
|
2005-04-17 08:30:15 +00:00
|
|
|
}
|
|
|
|
|
|
2013-10-11 22:41:59 +00:00
|
|
|
public function doUpdate() {
|
2019-03-15 00:23:26 +00:00
|
|
|
// Resolve the final list of URLs just before purging them (T240083)
|
|
|
|
|
$reboundDelayByUrl = $this->resolveReboundDelayByUrl();
|
|
|
|
|
|
|
|
|
|
// Send the immediate purges to CDN
|
|
|
|
|
self::purge( array_keys( $reboundDelayByUrl ) );
|
|
|
|
|
$immediatePurgeTimestamp = time();
|
|
|
|
|
|
|
|
|
|
// Get the URLs that need rebound purges, grouped by seconds of purge delay
|
|
|
|
|
$urlsWithReboundByDelay = [];
|
|
|
|
|
foreach ( $reboundDelayByUrl as $url => $delay ) {
|
|
|
|
|
if ( $delay > 0 ) {
|
|
|
|
|
$urlsWithReboundByDelay[$delay][] = $url;
|
2020-03-17 21:15:58 +00:00
|
|
|
}
|
|
|
|
|
}
|
2019-03-15 00:23:26 +00:00
|
|
|
// Enqueue delayed purge jobs for these URLs (usually only one job)
|
|
|
|
|
$jobs = [];
|
|
|
|
|
foreach ( $urlsWithReboundByDelay as $delay => $urls ) {
|
|
|
|
|
$jobs[] = new CdnPurgeJob( [
|
2020-03-17 21:15:58 +00:00
|
|
|
'urls' => $urls,
|
2019-03-15 00:23:26 +00:00
|
|
|
'jobReleaseTimestamp' => $immediatePurgeTimestamp + $delay
|
|
|
|
|
] );
|
2015-11-13 06:41:37 +00:00
|
|
|
}
|
2019-03-15 00:23:26 +00:00
|
|
|
JobQueueGroup::singleton()->lazyPush( $jobs );
|
2015-11-30 23:26:45 +00:00
|
|
|
}
|
|
|
|
|
|
2011-04-25 22:41:54 +00:00
|
|
|
/**
|
2017-11-01 20:55:24 +00:00
|
|
|
* Purges a list of CDN nodes defined in $wgCdnServers.
|
2011-04-25 22:41:54 +00:00
|
|
|
* $urlArr should contain the full URLs to purge as values
|
|
|
|
|
* (example: $urlArr[] = 'http://my.host/something')
|
|
|
|
|
*
|
2019-09-12 01:01:50 +00:00
|
|
|
* @param string[] $urls List of full URLs to purge
|
2011-04-25 22:41:54 +00:00
|
|
|
*/
|
2019-09-12 01:01:50 +00:00
|
|
|
public static function purge( array $urls ) {
|
2017-11-01 20:55:24 +00:00
|
|
|
global $wgCdnServers, $wgHTCPRouting;
|
2004-03-20 15:03:26 +00:00
|
|
|
|
2019-09-12 01:01:50 +00:00
|
|
|
if ( !$urls ) {
|
2007-06-19 21:13:17 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2004-03-20 15:03:26 +00:00
|
|
|
|
2015-11-30 23:26:45 +00:00
|
|
|
// Remove duplicate URLs from list
|
2019-09-12 01:01:50 +00:00
|
|
|
$urls = array_unique( $urls );
|
2015-11-30 23:26:45 +00:00
|
|
|
|
2019-09-12 01:01:50 +00:00
|
|
|
wfDebugLog( 'squid', __METHOD__ . ': ' . implode( ' ', $urls ) );
|
2012-10-17 00:00:07 +00:00
|
|
|
|
2015-12-29 19:45:23 +00:00
|
|
|
// Reliably broadcast the purge to all edge nodes
|
2016-05-16 19:50:44 +00:00
|
|
|
$ts = microtime( true );
|
2019-09-11 22:00:13 +00:00
|
|
|
$relayerGroup = MediaWikiServices::getInstance()->getEventRelayerGroup();
|
|
|
|
|
$relayerGroup->getRelayer( 'cdn-url-purges' )->notifyMulti(
|
2015-12-29 19:45:23 +00:00
|
|
|
'cdn-url-purges',
|
2016-05-16 19:50:44 +00:00
|
|
|
array_map(
|
|
|
|
|
function ( $url ) use ( $ts ) {
|
|
|
|
|
return [
|
|
|
|
|
'url' => $url,
|
|
|
|
|
'timestamp' => $ts,
|
|
|
|
|
];
|
|
|
|
|
},
|
2019-09-12 01:01:50 +00:00
|
|
|
$urls
|
2016-05-16 19:50:44 +00:00
|
|
|
)
|
2015-12-29 19:45:23 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Send lossy UDP broadcasting if enabled
|
2013-07-02 10:50:48 +00:00
|
|
|
if ( $wgHTCPRouting ) {
|
2019-09-12 01:01:50 +00:00
|
|
|
self::HTCPPurge( $urls );
|
2007-06-19 21:13:17 +00:00
|
|
|
}
|
2005-04-06 17:14:43 +00:00
|
|
|
|
2015-12-29 19:45:23 +00:00
|
|
|
// Do direct server purges if enabled (this does not scale very well)
|
2017-11-01 20:55:24 +00:00
|
|
|
if ( $wgCdnServers ) {
|
2019-09-12 01:01:50 +00:00
|
|
|
self::naivePurge( $urls );
|
2015-10-19 06:26:05 +00:00
|
|
|
}
|
2004-06-30 02:02:43 +00:00
|
|
|
}
|
|
|
|
|
|
2019-03-15 00:23:26 +00:00
|
|
|
/**
|
|
|
|
|
* @return string[] List of URLs
|
|
|
|
|
*/
|
|
|
|
|
public function getUrls() {
|
|
|
|
|
return array_keys( $this->resolveReboundDelayByUrl() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return int[] Map of (URL => rebound purge delay)
|
|
|
|
|
*/
|
|
|
|
|
private function resolveReboundDelayByUrl() {
|
|
|
|
|
/** @var Title $title */
|
|
|
|
|
|
|
|
|
|
// Avoid multiple queries for getCdnUrls() call
|
|
|
|
|
$lb = MediaWikiServices::getInstance()->getLinkBatchFactory()->newLinkBatch();
|
|
|
|
|
foreach ( $this->titleTuples as list( $title, $delay ) ) {
|
|
|
|
|
$lb->addObj( $title );
|
|
|
|
|
}
|
|
|
|
|
$lb->execute();
|
|
|
|
|
|
|
|
|
|
$reboundDelayByUrl = [];
|
|
|
|
|
|
|
|
|
|
// Resolve the titles into CDN URLs
|
|
|
|
|
foreach ( $this->titleTuples as list( $title, $delay ) ) {
|
|
|
|
|
foreach ( $title->getCdnUrls() as $url ) {
|
|
|
|
|
// Use the highest rebound for duplicate URLs in order to handle the most lag
|
|
|
|
|
$reboundDelayByUrl[$url] = max( $reboundDelayByUrl[$url] ?? 0, $delay );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ( $this->urlTuples as list( $url, $delay ) ) {
|
|
|
|
|
// Use the highest rebound for duplicate URLs in order to handle the most lag
|
|
|
|
|
$reboundDelayByUrl[$url] = max( $reboundDelayByUrl[$url] ?? 0, $delay );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $reboundDelayByUrl;
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-12 19:59:35 +00:00
|
|
|
/**
|
2019-09-12 01:01:50 +00:00
|
|
|
* Send Hyper Text Caching Protocol (HTCP) CLR requests
|
2013-10-11 22:41:59 +00:00
|
|
|
*
|
2011-07-12 19:59:35 +00:00
|
|
|
* @throws MWException
|
2019-09-12 01:01:50 +00:00
|
|
|
* @param string[] $urls Collection of URLs to purge
|
2011-07-12 19:59:35 +00:00
|
|
|
*/
|
2019-09-12 01:01:50 +00:00
|
|
|
private static function HTCPPurge( array $urls ) {
|
2013-07-02 10:50:48 +00:00
|
|
|
global $wgHTCPRouting, $wgHTCPMulticastTTL;
|
2005-04-06 17:14:43 +00:00
|
|
|
|
2013-10-11 22:41:59 +00:00
|
|
|
// HTCP CLR operation
|
|
|
|
|
$htcpOpCLR = 4;
|
2005-04-06 17:14:43 +00:00
|
|
|
|
2011-05-17 22:03:20 +00:00
|
|
|
// @todo FIXME: PHP doesn't support these socket constants (include/linux/in.h)
|
2013-04-20 17:18:13 +00:00
|
|
|
if ( !defined( "IPPROTO_IP" ) ) {
|
2006-10-16 19:12:56 +00:00
|
|
|
define( "IPPROTO_IP", 0 );
|
|
|
|
|
define( "IP_MULTICAST_LOOP", 34 );
|
|
|
|
|
define( "IP_MULTICAST_TTL", 33 );
|
|
|
|
|
}
|
2005-04-06 17:14:43 +00:00
|
|
|
|
|
|
|
|
// pfsockopen doesn't work because we need set_sock_opt
|
2009-11-03 17:49:49 +00:00
|
|
|
$conn = socket_create( AF_INET, SOCK_DGRAM, SOL_UDP );
|
2013-11-20 17:20:36 +00:00
|
|
|
if ( !$conn ) {
|
2013-07-02 10:42:39 +00:00
|
|
|
$errstr = socket_strerror( socket_last_error() );
|
|
|
|
|
wfDebugLog( 'squid', __METHOD__ .
|
2014-02-04 21:16:13 +00:00
|
|
|
": Error opening UDP socket: $errstr" );
|
2013-11-20 17:20:36 +00:00
|
|
|
|
2013-07-02 10:42:39 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2005-04-06 17:14:43 +00:00
|
|
|
|
2013-07-02 10:42:39 +00:00
|
|
|
// Set socket options
|
|
|
|
|
socket_set_option( $conn, IPPROTO_IP, IP_MULTICAST_LOOP, 0 );
|
|
|
|
|
if ( $wgHTCPMulticastTTL != 1 ) {
|
2013-10-11 22:41:59 +00:00
|
|
|
// Set multicast time to live (hop count) option on socket
|
2013-07-02 10:42:39 +00:00
|
|
|
socket_set_option( $conn, IPPROTO_IP, IP_MULTICAST_TTL,
|
|
|
|
|
$wgHTCPMulticastTTL );
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2013-12-24 23:22:58 +00:00
|
|
|
// Get sequential trx IDs for packet loss counting
|
2019-05-31 23:24:56 +00:00
|
|
|
$idGenerator = MediaWikiServices::getInstance()->getGlobalIdGenerator();
|
|
|
|
|
$ids = $idGenerator->newSequentialPerNodeIDs(
|
2019-09-12 01:01:50 +00:00
|
|
|
'squidhtcppurge', 32,
|
|
|
|
|
count( $urls ),
|
|
|
|
|
$idGenerator::QUICK_VOLATILE
|
2013-12-24 23:22:58 +00:00
|
|
|
);
|
|
|
|
|
|
2019-09-12 01:01:50 +00:00
|
|
|
foreach ( $urls as $url ) {
|
2013-07-02 10:42:39 +00:00
|
|
|
if ( !is_string( $url ) ) {
|
|
|
|
|
throw new MWException( 'Bad purge URL' );
|
|
|
|
|
}
|
2013-10-11 22:41:59 +00:00
|
|
|
$url = self::expand( $url );
|
2013-07-02 10:50:48 +00:00
|
|
|
$conf = self::getRuleForURL( $url, $wgHTCPRouting );
|
2013-07-02 10:42:39 +00:00
|
|
|
if ( !$conf ) {
|
|
|
|
|
wfDebugLog( 'squid', __METHOD__ .
|
2014-02-04 21:16:13 +00:00
|
|
|
"No HTCP rule configured for URL {$url} , skipping" );
|
2013-07-02 10:42:39 +00:00
|
|
|
continue;
|
|
|
|
|
}
|
2013-07-02 10:50:48 +00:00
|
|
|
|
2013-08-24 15:06:25 +00:00
|
|
|
if ( isset( $conf['host'] ) && isset( $conf['port'] ) ) {
|
2013-07-02 10:50:48 +00:00
|
|
|
// Normalize single entries
|
2016-02-17 09:09:32 +00:00
|
|
|
$conf = [ $conf ];
|
2013-07-02 10:50:48 +00:00
|
|
|
}
|
2013-08-24 15:06:25 +00:00
|
|
|
foreach ( $conf as $subconf ) {
|
2013-07-02 10:50:48 +00:00
|
|
|
if ( !isset( $subconf['host'] ) || !isset( $subconf['port'] ) ) {
|
|
|
|
|
throw new MWException( "Invalid HTCP rule for URL $url\n" );
|
|
|
|
|
}
|
2013-07-02 10:42:39 +00:00
|
|
|
}
|
2005-04-06 17:14:43 +00:00
|
|
|
|
2013-07-02 10:42:39 +00:00
|
|
|
// Construct a minimal HTCP request diagram
|
|
|
|
|
// as per RFC 2756
|
|
|
|
|
// Opcode 'CLR', no response desired, no auth
|
2013-12-24 23:22:58 +00:00
|
|
|
$htcpTransID = current( $ids );
|
|
|
|
|
next( $ids );
|
2005-04-06 17:14:43 +00:00
|
|
|
|
2013-07-02 10:42:39 +00:00
|
|
|
$htcpSpecifier = pack( 'na4na*na8n',
|
|
|
|
|
4, 'HEAD', strlen( $url ), $url,
|
|
|
|
|
8, 'HTTP/1.0', 0 );
|
2005-04-06 17:14:43 +00:00
|
|
|
|
2013-07-02 10:42:39 +00:00
|
|
|
$htcpDataLen = 8 + 2 + strlen( $htcpSpecifier );
|
|
|
|
|
$htcpLen = 4 + $htcpDataLen + 2;
|
2005-04-06 17:14:43 +00:00
|
|
|
|
2013-07-02 10:42:39 +00:00
|
|
|
// Note! Squid gets the bit order of the first
|
|
|
|
|
// word wrong, wrt the RFC. Apparently no other
|
|
|
|
|
// implementation exists, so adapt to Squid
|
|
|
|
|
$htcpPacket = pack( 'nxxnCxNxxa*n',
|
|
|
|
|
$htcpLen, $htcpDataLen, $htcpOpCLR,
|
|
|
|
|
$htcpTransID, $htcpSpecifier, 2 );
|
|
|
|
|
|
2013-07-01 13:16:43 +00:00
|
|
|
wfDebugLog( 'squid', __METHOD__ .
|
2014-02-04 21:16:13 +00:00
|
|
|
"Purging URL $url via HTCP" );
|
2013-08-24 15:06:25 +00:00
|
|
|
foreach ( $conf as $subconf ) {
|
2013-07-02 10:50:48 +00:00
|
|
|
socket_sendto( $conn, $htcpPacket, $htcpLen, 0,
|
|
|
|
|
$subconf['host'], $subconf['port'] );
|
|
|
|
|
}
|
2005-04-06 17:14:43 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-12 01:01:50 +00:00
|
|
|
/**
|
|
|
|
|
* Send HTTP PURGE requests for each of the URLs to all of the cache servers
|
|
|
|
|
*
|
|
|
|
|
* @param string[] $urls
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
private static function naivePurge( array $urls ) {
|
|
|
|
|
global $wgCdnServers, $wgVersion;
|
|
|
|
|
|
|
|
|
|
$reqs = [];
|
|
|
|
|
foreach ( $urls as $url ) {
|
|
|
|
|
$urlInfo = wfParseUrl( self::expand( $url ) );
|
|
|
|
|
$urlHost = strlen( $urlInfo['port'] ?? null )
|
|
|
|
|
? IP::combineHostAndPort( $urlInfo['host'], $urlInfo['port'] )
|
|
|
|
|
: $urlInfo['host'];
|
|
|
|
|
$urlPath = strlen( $urlInfo['query'] ?? null )
|
|
|
|
|
? wfAppendQuery( $urlInfo['path'], $urlInfo['query'] )
|
|
|
|
|
: $urlInfo['path'];
|
|
|
|
|
$baseReq = [
|
|
|
|
|
'method' => 'PURGE',
|
|
|
|
|
'url' => $urlPath,
|
|
|
|
|
'headers' => [
|
|
|
|
|
'Host' => $urlHost,
|
|
|
|
|
'Connection' => 'Keep-Alive',
|
|
|
|
|
'Proxy-Connection' => 'Keep-Alive',
|
|
|
|
|
'User-Agent' => "MediaWiki/$wgVersion " . __CLASS__
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
foreach ( $wgCdnServers as $server ) {
|
|
|
|
|
$reqs[] = ( $baseReq + [ 'proxy' => $server ] );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$http = new MultiHttpClient( [ 'maxConnsPerHost' => 8, 'usePipelining' => true ] );
|
|
|
|
|
$http->runMulti( $reqs );
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-24 21:57:25 +00:00
|
|
|
/**
|
|
|
|
|
* Expand local URLs to fully-qualified URLs using the internal protocol
|
|
|
|
|
* and host defined in $wgInternalServer. Input that's already fully-
|
|
|
|
|
* qualified will be passed through unchanged.
|
|
|
|
|
*
|
|
|
|
|
* This is used to generate purge URLs that may be either local to the
|
|
|
|
|
* main wiki or include a non-native host, such as images hosted on a
|
|
|
|
|
* second internal server.
|
|
|
|
|
*
|
|
|
|
|
* Client functions should not need to call this.
|
|
|
|
|
*
|
2013-10-11 22:41:59 +00:00
|
|
|
* @param string $url
|
2006-05-24 21:57:25 +00:00
|
|
|
* @return string
|
|
|
|
|
*/
|
2019-09-12 00:08:52 +00:00
|
|
|
private static function expand( $url ) {
|
2011-09-07 14:15:03 +00:00
|
|
|
return wfExpandUrl( $url, PROTO_INTERNAL );
|
2006-05-24 21:57:25 +00:00
|
|
|
}
|
2012-10-10 18:13:40 +00:00
|
|
|
|
2012-04-06 20:27:10 +00:00
|
|
|
/**
|
|
|
|
|
* Find the HTCP routing rule to use for a given URL.
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $url URL to match
|
2013-07-02 10:50:48 +00:00
|
|
|
* @param array $rules Array of rules, see $wgHTCPRouting for format and behavior
|
2012-04-06 20:27:10 +00:00
|
|
|
* @return mixed Element of $rules that matched, or false if nothing matched
|
|
|
|
|
*/
|
2013-10-11 22:41:59 +00:00
|
|
|
private static function getRuleForURL( $url, $rules ) {
|
2012-04-06 20:27:10 +00:00
|
|
|
foreach ( $rules as $regex => $routing ) {
|
|
|
|
|
if ( $regex === '' || preg_match( $regex, $url ) ) {
|
|
|
|
|
return $routing;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-11-20 17:20:36 +00:00
|
|
|
|
2012-04-06 20:27:10 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
2004-01-30 16:06:22 +00:00
|
|
|
}
|