abhikmitra / hack-memcache-mysql-web-server

Barebones Server in HHVM using Hack . Uses Memcache and MySQL

Home Page:https://abhikmitra.github.io/blog/hack-php/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Basic Webserver in Hack (Hacklang)

Why does this Repo exist ?

I used this repo to learn hack . One of the problems I faced while learning Hack was availaibility of a basic web scaffolding to quickly setup a web server purely in Hack.

Why do we need a scaffolding or prior art ?

A scaffolding helps a beginner in many ways

  • Code Organization
  • Have something up and running quicky.
  • Saves effort so that people do not need to create a scaffolding repoo everytime.

This repo is meant to address all of these points .

Where can I read more about the process and design choices ?

I have a blog post detailing the steps and some of my design choices .

Tell me more.

This repo comes with the following setup

  • Completely in Hack
  • Request routing Setup
  • Views and Controllers Pattern (Should be pretty easy to grasp for people coming from NodeJs/ASP.NET background)
  • Connection to MySQL
  • Connection memcache
  • Separation of API and WebPage Controllers
  • VsCode Setup , the folder /ui-server/.vscode has all the vscode specific configs

The web app has login/signup flow and the session id flow where the sessionId gets stored in memcache and the user details get stored in MySQL. Once logged in , the user lands in homepage which would typically be a react app.

How do I run this ?

  • Open /ui-server in VSCode (Do not open the current top level as then Vs Code - hack wont show type errors)
  • Of course make sure you have VsCode Hack extension.
  • composer i to install all packges
  • composer dump-autoload to autoload all packages
  • hh_client start make sure hh_client is started so that type hints work in VS Code,
  • Make sure you have memcached setup. Here is a guide
  • Have mySQL setup . I have used a free instance in heroku. Feel free to install locally also.
  • Change Constants.js to reflect the proper connection strings for Memcached and MySql.
  • Start the server (make sure the current directory is /ui-server)
  • hhvm -c config.ini -m server -p 8080

How do I debug this ?

Once you have the server up and running, you need to attach your server. Open VsCode and go to the Run pane and click on HHVM: Attach to the UI Server

How do I add a new route ?

Just add a Controller and make sure it or any of its parents implement IRoutableController . Once that is done , go to the Run pane and run the HHVM:Update Router file. That would regenerate the AutoGeneratedRouterBase.php file.

Are these best practices.

Nope , not even close . I tried to structure it based on what I have seen in otehr stack and these are by no means perfect . Use this as a scaffolding if you are new to Hack .

About

Barebones Server in HHVM using Hack . Uses Memcache and MySQL

https://abhikmitra.github.io/blog/hack-php/

License:MIT License


Languages

Language:Hack 98.5%Language:CSS 1.3%Language:JavaScript 0.2%