hhvm -m server -p 8080 hhvm whatever.php
# binaries # hack to php /usr/bin/h2tp /usr/bin/hack_remove_soft_types /usr/bin/hackificator /usr/bin/hh_client /usr/bin/hh_format /usr/bin/hh_server /usr/bin/hhvm # php containers code /usr/share/hhvm/hack/hacklib/containers # relevant config files /etc/apache2/mods-available/hhvm_proxy_fcgi.conf /etc/default/hhvm /etc/hhvm/php.ini /etc/hhvm/server.ini /etc/init.d/hhvm # logger /var/log/hhvm/error.log
h2tp <src> <dst> --no-collections
controllare la procedura dal sito docs
wget -O - http://dl.hhvm.com/conf/hhvm.gpg.key | sudo apt-key add - echo deb http://dl.hhvm.com/ubuntu trusty main | sudo tee /etc/apt/sources.list.d/hhvm.list sudo apt-get update sudo apt-get install hhvm
una volta installato il pacchetto distro aggiornato verificare i files installati per intergrarsi in apache
# vi /etc/apache2/mods-available/hhvm_proxy_fcgi.conf # ProxyPassMatch ^/(.+\.(hh|php)(/.*)?)$ fcgi://127.0.0.1:9000/var/www/$1 ProxyPassMatch ^/(.+\.(hh)(/.*)?)$ fcgi://127.0.0.1:9000/var/www/$1
Setting up hhvm (3.17.1~xenial) ... ******************************************************************** * HHVM is installed. * * Running PHP web scripts with HHVM is done by having your * webserver talk to HHVM over FastCGI. Install nginx or Apache, * and then: * $ sudo /usr/share/hhvm/install_fastcgi.sh * $ sudo /etc/init.d/hhvm restart * (if using nginx) $ sudo /etc/init.d/nginx restart * (if using apache) $ sudo /etc/init.d/apache restart * * Detailed FastCGI directions are online at: * https://github.com/facebook/hhvm/wiki/FastCGI * * If you're using HHVM to run web scripts, you probably want it * to start at boot: * $ sudo update-rc.d hhvm defaults * * Running command-line scripts with HHVM requires no special setup: * $ hhvm whatever.php * * You can use HHVM for /usr/bin/php even if you have php-cli * installed: * $ sudo /usr/bin/update-alternatives \ * --install /usr/bin/php php /usr/bin/hhvm 60 ********************************************************************
it's not exactly multitasking, it still allows you to run separate blocks of code in parallel: while one is waiting on something that is not blocked on CPU (e.g. for an API response to come back), the other be executed already.
<?hh
async function api(): Awaitable<string> {
//
// Let's pretend we've just executed an API call
// and are now waiting for it to come back with
// a response. While that's being done, CPU should
// be free to execute code elsewhere.
//
await SleepWaitHandle::create(1000); // 1ms
return 'api result';
}
async function cpu(): Awaitable<string> {
//
// Let's pretend we're doing some CPU-heavy stuff.
//
usleep(500); // 0.5ms
return 'cpu result';
}
$time = microtime(true);
//
// Execute both code blocks - while api() is waiting
// for the response, CPU-bound code will already be
// executed (thus losing less time idling until we
// hear back from the API call.)
// After that, wait until both async blocks are done
// and get their results.
//
$asyncApi = api();
$asyncCpu = cpu();
$resultApi = $asyncApi->getWaitHandle()->join();
$resultCpu = $asyncCpu->getWaitHandle()->join();
//
// Time elapsed will only be slightly over 1ms,
// instead of the expected 1ms (API) + 0.5ms (CPU)
// because we were able to execute the CPU-intensive
// code while we were waiting on the API response.
//
echo microtime(true) - $time;