MCRouter::__construct

Initialize an MCRouter handle

public function __construct(
  array<string, mixed> $options,
  string $pid = '',
): void;

See: https://github.com/facebook/mcrouter/wiki See: https://github.com/facebook/mcrouter/blob/master/ mcrouter/mcrouter_options_list.h

Parameters

  • array<string, mixed> $options
  • string $pid = ''

Returns

  • void

Examples

The following example shows you how to explicitly create an instance of MCRouter using new, by definition, its constructor. You must create a configuration string (or provide a configuration file that contains appropriate configuration information), and, optionally, a persistence identifier can bet passed as the second parameter to the constructor.

function construct_mcrouter(): void {
  $servers = Vector {\getenv('HHVM_TEST_MCROUTER')};
  // For many use cases, calling MCRouter::createSimple($servers) would
  // suffice here. But this shows you how to explicitly create the configuration
  // options for creating an instance of MCRouter
  $options = array(
    'config_str' => \json_encode(
      array(
        'pools' => array(
          'P' => array(
            'servers' => $servers,
          ),
        ),
        'route' => 'PoolRoute|P',
      ),
    ),
  );
  $mc = new \MCRouter($options); // could also pass a persistence id string here
  \var_dump($mc is \MCRouter);
}

construct_mcrouter();
Output
bool(true)