23use Wikimedia\Assert\Assert;
38 $this->urls = $urlArr;
43 Assert::parameterType( __CLASS__, $update,
'$update' );
44 '@phan-var self $update';
46 $this->urls = array_merge( $this->urls, $update->urls );
59 foreach ( $titles as
$title ) {
60 $urlArr = array_merge( $urlArr,
$title->getCdnUrls() );
75 JobQueueGroup::singleton()->lazyPush(
new CdnPurgeJob( [
76 'urls' => $this->urls,
89 public static function purge( array $urlArr ) {
97 $urlArr = array_unique( $urlArr );
99 wfDebugLog(
'squid', __METHOD__ .
': ' . implode(
' ', $urlArr ) );
102 $ts = microtime(
true );
103 $relayerGroup = MediaWikiServices::getInstance()->getEventRelayerGroup();
104 $relayerGroup->getRelayer(
'cdn-url-purges' )->notifyMulti(
107 function ( $url ) use ( $ts ) {
125 $maxSocketsPerCdn = 8;
128 $urlsPerSocket = 400;
129 $socketsPerCdn = ceil( count( $urlArr ) / $urlsPerSocket );
130 if ( $socketsPerCdn > $maxSocketsPerCdn ) {
131 $socketsPerCdn = $maxSocketsPerCdn;
135 $chunks = array_chunk( $urlArr, ceil( count( $urlArr ) / $socketsPerCdn ) );
137 foreach ( $chunks as $chunk ) {
139 foreach ( $chunk as $url ) {
140 $client->queuePurge( self::expand( $url ) );
142 $pool->addClient( $client );
163 if ( !defined(
"IPPROTO_IP" ) ) {
164 define(
"IPPROTO_IP", 0 );
165 define(
"IP_MULTICAST_LOOP", 34 );
166 define(
"IP_MULTICAST_TTL", 33 );
170 $conn = socket_create( AF_INET, SOCK_DGRAM, SOL_UDP );
172 $errstr = socket_strerror( socket_last_error() );
174 ": Error opening UDP socket: $errstr" );
180 socket_set_option( $conn, IPPROTO_IP, IP_MULTICAST_LOOP, 0 );
183 socket_set_option( $conn, IPPROTO_IP, IP_MULTICAST_TTL,
192 foreach ( $urlArr as $url ) {
193 if ( !is_string( $url ) ) {
200 "No HTCP rule configured for URL {$url} , skipping" );
204 if ( isset( $conf[
'host'] ) && isset( $conf[
'port'] ) ) {
208 foreach ( $conf as $subconf ) {
209 if ( !isset( $subconf[
'host'] ) || !isset( $subconf[
'port'] ) ) {
210 throw new MWException(
"Invalid HTCP rule for URL $url\n" );
217 $htcpTransID = current( $ids );
220 $htcpSpecifier = pack(
'na4na*na8n',
221 4,
'HEAD', strlen( $url ), $url,
224 $htcpDataLen = 8 + 2 + strlen( $htcpSpecifier );
225 $htcpLen = 4 + $htcpDataLen + 2;
230 $htcpPacket = pack(
'nxxnCxNxxa*n',
231 $htcpLen, $htcpDataLen, $htcpOpCLR,
232 $htcpTransID, $htcpSpecifier, 2 );
235 "Purging URL $url via HTCP" );
236 foreach ( $conf as $subconf ) {
237 socket_sendto( $conn, $htcpPacket, $htcpLen, 0,
238 $subconf[
'host'], $subconf[
'port'] );
268 foreach ( $rules as $regex => $routing ) {
269 if ( $regex ===
'' || preg_match( $regex, $url ) ) {
$wgCdnReboundPurgeDelay
If set, any SquidPurge call on a URL or URLs will send a second purge no less than this many seconds ...
$wgHTCPRouting
Routing configuration for HTCP multicast purging.
$wgCdnServers
List of proxy servers to purge on changes; default port is 80.
$wgHTCPMulticastTTL
HTCP multicast TTL.
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
wfDebugLog( $logGroup, $text, $dest='all', array $context=[])
Send a line to a supplementary debug log file, if configured, or main debug log if not.
Handles purging the appropriate CDN objects given a list of URLs or Title instances.
static newFromTitles( $titles, $urlArr=[])
Create an update object from an array of Title objects, or a TitleArray object.
__construct(array $urlArr)
static HTCPPurge(array $urlArr)
Send Hyper Text Caching Protocol (HTCP) CLR requests.
static getRuleForURL( $url, $rules)
Find the HTCP routing rule to use for a given URL.
string[] $urls
Collection of URLs to purge.
static purge(array $urlArr)
Purges a list of CDN nodes defined in $wgCdnServers.
doUpdate()
Purges the list of URLs passed to the constructor.
static expand( $url)
Expand local URLs to fully-qualified URLs using the internal protocol and host defined in $wgInternal...
merge(MergeableUpdate $update)
Merge this update with $update.
Job to purge a set of URLs from CDN.
Class representing a list of titles The execute() method checks them all for existence and adds them ...
An HTTP 1.0 client built for the purposes of purging Squid and Varnish.
Represents a title within MediaWiki.
static newSequentialPerNodeIDs( $bucket, $bits, $count, $flags=0)
Return IDs that are sequential only for this node and bucket.
Interface that deferrable updates should implement.
Interface that deferrable updates can implement to signal that updates can be combined.