MCRouter::__construct

Initialize an MCRouter handle

Description

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

Initialize an MCRouter handle

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 = ""

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.

<?hh

namespace Hack\UserDocumentation\API\Examples\MCRouter\MCrouter\Construct;

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 instanceof \MCRouter);
}

construct_mcrouter();
Output
bool(true)