Basic Usage: Command Line

In command-line (cli) mode, you run the hhvm binary from the command-line, execute the script and then exit HHVM immediately when the script completes.

Here is an example of how to run a script in HHVM cli mode. Take the following PHP script:

<?hh

namespace HHVM\UserDocumentation\BasicUsage\Examples\CommandLine;

function fibonacci(int $number): int {
  return intval(round(pow((sqrt(5) + 1) / 2, $number) / sqrt(5)));
}

function main(array<string> $argv) {
  echo 'The ' . $argv[1] . ' number in fibonacci is: '
      . fibonacci((int) $argv[1]) . PHP_EOL;
}

main($argv);
Output
The 10 number in fibonacci is: 55

At the command-line, you would execute the script as follows:

% hhvm /path/to/fib.php 10

You specify the hhvm binary, the path to fib.php and an argument to the script (arguments to scripts do not exist in all cases, of course).

The 10 number in fibonacci is: 55