MediaWiki  REL1_24
RedisPubSubFeedEngine.php
Go to the documentation of this file.
00001 <?php
00002 
00039 class RedisPubSubFeedEngine implements RCFeedEngine {
00040 
00044     public function send( array $feed, $line ) {
00045         $parsed = wfParseUrl( $feed['uri'] );
00046         $server = $parsed['host'];
00047         $options = array( 'serializer' => 'none' );
00048         $channel = 'rc';
00049 
00050         if ( isset( $parsed['port'] ) ) {
00051             $server .= ":{$parsed['port']}";
00052         }
00053         if ( isset( $parsed['query'] ) ) {
00054             parse_str( $parsed['query'], $options );
00055         }
00056         if ( isset( $parsed['pass'] ) ) {
00057             $options['password'] = $parsed['pass'];
00058         }
00059         if ( isset( $parsed['path'] ) ) {
00060             $channel = str_replace( '/', '.', ltrim( $parsed['path'], '/' ) );
00061         }
00062         $pool = RedisConnectionPool::singleton( $options );
00063         $conn = $pool->getConnection( $server );
00064         if ( $conn !== false ) {
00065             $conn->publish( $channel, $line );
00066             return true;
00067         } else {
00068             return false;
00069         }
00070     }
00071 }