My First Post      My Facebook Profile      My MeOnShow Profile      W3LC Facebook Page      Learners Consortium Group      Job Portal      Shopping @Yeyhi.com









Friday, March 6, 2020

First Hello World using Hack & HHVM from Facebook

1. Install HHVM on MacOS via Homebrew:
brew tap hhvm/hhvm
brew install hhvm

The out-of-the-box HHVM configuration won't need tweaking by most new users. Notably, the JIT compiler that gives HHVM its speed is on by default. If you want to take a look at the configuration used, it's at /usr/local/etc/hhvm/php.ini in MacOS.



2. Test: After installing HHVM, change to the directory where your code lives, and start up HHVM:

hhvm -m server -p 8080
-m represents the mode and here indicates that HHVM is running in HTTP server mode.
-p configures the TCP port that HHVM uses to listen to HTTP requests. The default port is 80, the standard HTTP port. However, that port requires root access, so for this example, we will use port 8080.

This will start the server as follows and then you can test on browser.


3. Write a simple "Hello World" program named hello.hack:

<<__entrypoint>> function main(): noreturn{ echo "Hello World in Hack Language! \nThis is Anwar Jamal Faiz"; exit(0); }

Save this hello.hack in the same directory that you ran the hhvm command from above. Then, load http://localhost:8080/hello.hack in your browser and verify you see "Hello World!" appear.


See in browser:
You may also write the program as:
<<__entrypoint>>
function main(): noreturn{
  echo "Hello World in Hack Language! \nThis is Anwar Jamal Faiz";
  exit(0);
}




4.  You can directly run file using hhvm itself.

$ hhvm hello.hack




Note: You can configure HHVM too. Running HHVM automatically at boot as a service (instead of just on the command line as above) unfortunately does require some configuration. See the proxygen documentation for details. However, default settings are okay for any average usecase.


No comments:

Post a Comment