MediaWiki master
RedisPubSubFeedEngine.php
Go to the documentation of this file.
1<?php
7namespace MediaWiki\RCFeed;
8
11
39
46 public function send( array $feed, $line ) {
47 $urlUtils = MediaWikiServices::getInstance()->getUrlUtils();
48 $parsed = $urlUtils->parse( $feed['uri'] );
49 // @phan-suppress-next-line PhanTypeArraySuspiciousNullable Valid URL
50 $server = $parsed['host'];
51 $options = [ 'serializer' => 'none' ];
52 $channel = 'rc';
53
54 if ( isset( $parsed['port'] ) ) {
55 $server .= ":{$parsed['port']}";
56 }
57 if ( isset( $parsed['query'] ) ) {
58 parse_str( $parsed['query'], $options );
59 }
60 if ( isset( $parsed['pass'] ) ) {
61 $options['password'] = $parsed['pass'];
62 }
63 if ( isset( $parsed['path'] ) ) {
64 $channel = str_replace( '/', '.', ltrim( $parsed['path'], '/' ) );
65 }
66 $pool = RedisConnectionPool::singleton( $options );
67 $conn = $pool->getConnection( $server );
68 if ( $conn !== false ) {
69 $conn->publish( $channel, $line );
70 return true;
71 }
72
73 return false;
74 }
75}
77class_alias( RedisPubSubFeedEngine::class, 'RedisPubSubFeedEngine' );
Service locator for MediaWiki core services.
static getInstance()
Returns the global default instance of the top level service locator.
Base class for RCFeed implementations that use RCFeedFormatter.
Send recent change to a Redis Pub/Sub channel.
Manage one or more Redis client connection.