MediaWiki master
RedisPubSubFeedEngine.php
Go to the documentation of this file.
1<?php
21namespace MediaWiki\RCFeed;
22
24
52
59 public function send( array $feed, $line ) {
60 $parsed = wfGetUrlUtils()->parse( $feed['uri'] );
61 // @phan-suppress-next-line PhanTypeArraySuspiciousNullable Valid URL
62 $server = $parsed['host'];
63 $options = [ 'serializer' => 'none' ];
64 $channel = 'rc';
65
66 if ( isset( $parsed['port'] ) ) {
67 $server .= ":{$parsed['port']}";
68 }
69 if ( isset( $parsed['query'] ) ) {
70 parse_str( $parsed['query'], $options );
71 }
72 if ( isset( $parsed['pass'] ) ) {
73 $options['password'] = $parsed['pass'];
74 }
75 if ( isset( $parsed['path'] ) ) {
76 $channel = str_replace( '/', '.', ltrim( $parsed['path'], '/' ) );
77 }
78 $pool = RedisConnectionPool::singleton( $options );
79 $conn = $pool->getConnection( $server );
80 if ( $conn !== false ) {
81 $conn->publish( $channel, $line );
82 return true;
83 }
84
85 return false;
86 }
87}
89class_alias( RedisPubSubFeedEngine::class, 'RedisPubSubFeedEngine' );
wfGetUrlUtils()
Base class for RCFeed implementations that use RCFeedFormatter.
Send recent change to a Redis Pub/Sub channel.
Helper class to manage Redis connections.