SilverStripe on HHVM: Part One

Posted by Jared Kipe on | 0 Comments

Tags: , ,

Just the Basics and Setup (with Video)

Getting SilverStripe working on HHVM is possible right now! Follow along as I show you how to work around the incompatibilities that need to be addressed before getting a single page to load.

Brief Justification

PHP is not a fast language.  As a loosely typed and interpreted language, it will never compete with strongly typed and compiled languages like C. (Python and Ruby are in the same boat here) The original HipHopPHP implementation was a static compiler (to C++), and was certainly fast.  However, there was a big penalty to pay for this speed, namely some of the dynamic (and arguably evil) elements of the language such as eval(), and the need to take a break while your code compiles.

HHVM takes a page out of Java and C#'s book by implementing a virtual machine and using a Just In Time (JIT) compiler to transform PHP into bytecode for the virtual machine.

On a side note, Java is becoming more and more popular in web programming, and not necessarily because of the language Java! The Java virtual machine can be used to run a wide variety of languages and some languages have been specifically programmed for running in JVM e.g. Clojure and Scala.

Ultimately, competition with the traditional Zend PHP engine is only good for all PHP runtimes and programmers.

PDO if you use MySQL

Currently HHVM does not provide the mysqli extension/driver, and SilverStripe uses mysqli for its MySQL integration.  Thankfully, HHVM does support the PDO (PHP Data Objects) extension, and SilverStripe offers a relatively easy to extend database abstraction layer.

I wrote a simple SilverStripe extension (by following the lead of the MSSQL and SQLite extensions), you can download it on my GitHub.

System Setup and HHVM Install

You can use the semi official installation guide for HHVM found on Facebook's GitHub.

I'm using NGINX and reverse proxying into the HHVM HTTP server. My setup isn't particularly advanced, or optimized, but you can download them here for completeness sake (*soon*).

SilverStripe Framework Edits

/framework/main.php

// @top afer <?php
if ($_SERVER['SERVER_SOFTWARE'] == 'HPHP') {
	date_default_timezone_set('America/Los_Angeles');
	$_SERVER['REQUEST_URI'] = $_SERVER['HTTP_REQUEST_URI'];
	$_SERVER['QUERY_STRING'] = trim($_SERVER['QUERY_STRING'], '&');
}

Targets HHVM as the server software to clean up some things from the reverse proxy, and sets default timezone.

/framework/filesystem/FileFinder.php

// @line 73
//$this->options = array_merge(Object::static_lookup($class, 'default_options'), $this->options);
$this->options = array_merge($class::$default_options, $this->options);

Currently, this just doesn't work, and will prevent the manifest from being built. It isn't as much of a show stopper as the big 'magic method' bug though.

/framework/model/DataObject.php

// @line 111
public $record;

Visibility on $record needs to become public for the edit to Versioned.php to be possible.

// @line 447
//gc_collect_cycles();

HHVM does not support circular garbage collecting, and will remind you in the error logs if you don't comment this out.

/framework/model/Versioned.php

// @line 338
// make all $dataObject->var into $dataObject->record['var']

This is the 'magic method' bug I referred to earlier, and will be discussed in more detail later.

/framework/core/Core.php

// @line 57
//gc_enable();

Keep those logs clean by not trying to use garbage collection.

Edits for doing clean install

/framework/_register_database.php

// @bottom
DatabaseAdapterRegistry::register(
        array(
              	'class' => 'PDOMySQLDatabase',
                'title' => 'PDO MySQL 5.0+',
                'helperPath' => 'pdomysql/code/PDOMySQLDatabaseConfigurationHelper.php',
                'supported' => (class_exists('PDO')),
                'missingExtensionText' => 'The PDO PHP extension is not available. Please install or enable one of them and refresh this page.',
                'fields' => array(
                        'server' => array(
                                'title' => 'Database server',
                                'default' => 'localhost'
                        ),
                        'port' => array(
                                'title' => 'Database port:
leave blank if using localhost', 'default' => '' ), 'username' => array( 'title' => 'Database username', 'default' => 'root' ), 'password' => array( 'title' => 'Database password', 'default' => '', 'type' => 'password' ), 'database' => array( 'title' => 'Database name', 'default' => 'ss_mysite' ), ), ) );

Part of the PDOMySQL installation.

/install.php

// @ top after <?php
if ($_SERVER['SERVER_SOFTWARE'] == 'HPHP') {
	date_default_timezone_set('America/Los_Angeles');
	$_SERVER['REQUEST_URI'] = $_SERVER['HTTP_REQUEST_URI'];
	$_SERVER['QUERY_STRING'] = trim($_SERVER['QUERY_STRING'], '&');
}

Targets HHVM as the server software to clean up some things from the reverse proxy, and sets default timezone.

/framework/dev/install/install.php5

// @line ~695
if(false && !$result) {

HHVM does not currently support all php.ini keys, and is actively working on improving this, but for now we can just skip this test. (our /framework/main.php edit still sets a timezone)

After Installation: /mysite/_config.php

// @line bottom
Security::setDefaultAdmin('admin','demo');

Something doesn't quite work out with the installation and it prevents you from using your admin user. Since you cannot do much in the admin interface now anyway, this isn't a huge deal. If you are trying this out on a prior SilverStripe installation, your old passwords will still work.


Post your comment

Comments

No one has commented on this page yet.

RSS feed for comments on this page | RSS feed for all comments