Back to Hhvm

__construct

hphp/hack/manual/apis/Classes/MCRouter/0.__construct.md

latest1.8 KB
Original Source

:::info[Note] This is a point-in-time snapshot of the API documentation from January 2026. Going forward, we will not be maintaining a public copy of these references, and recommend users to refer to the built-in signature helpers available in the Hack LSP instead for complete and up-to-date information. :::

Initialize an MCRouter handle

Hack
public function __construct(
  darray<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

  • darray<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.

basic-usage.hack
$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 = darray[
  'config_str' => \json_encode(
    darray[
      'pools' => darray[
        'P' => darray[
          'servers' => $servers,
        ],
      ],
      'route' => 'PoolRoute|P',
    ],
  ),
];
$mc = new \MCRouter($options); // could also pass a persistence id string here
\var_dump($mc is \MCRouter);
```.hhvm.expectf
bool(true)
```.example.hhvm.out
bool(true)
```.skipif
\Hack\UserDocumentation\API\Examples\MCRouter\skipif();
<!-- HHAPIDOC -->