HipHop

From MediaWiki.org
Jump to: navigation, search

HipHop is an open source PHP to C++ translator developed by Facebook.

HipHop support in MediaWiki is currently at an early stage of development. It should not be used by anyone except for developers wishing to improve the HipHop support.

Contents

[edit] Running MediaWiki under HipHop

For information on installing HipHop, see the HipHop wiki. To compile MediaWiki with HipHop:

cd /path/to/wiki/maintenance/hiphop
hphpi -f make

This will create a compiled binary at build/persistent/mediawiki-hphp. To run a test server, use:

./run-server

This will start an HTTP server which listens on port 8080. MediaWiki will be accessible at http://localhost:8080/index.php.

To run a maintenance script:

build/persistent/mediawiki-hphp -f maintenance/<SCRIPT_NAME>.php

Currently, to reduce build time, only a small subset of MediaWiki files are compiled by default.

[edit] Development guidelines

[edit] Interpreter

HipHop has both a compiler and an interpreter. For the maximum speedup, we want as much code to be compiled as possible. However, the build process is slow (~30 minutes), so it seems reasonable to interpret the configuration files.

It's possible to interpret arbitrary code with eval() or include() called from a compiled program. In fact, this is how the hphpi binary works -- it is written in PHP.

File level code can be compiled like any other code. To execute compiled files, use:

require( MWInit::compiledPath( 'path/to/File.php' ) );

where the path is relative to $IP. To cause a file to be executed in interpreted mode, use:

require( MWInit::interpretedPath( 'path/to/File.php' ) );

Both of these forms will work in Zend PHP. When you want to make sure a class or function exists, do not use code such as:

require_once( dirname( __FILE__ ) . '/File.php' ) );

This will cause the file to be interpreted, regardless of whether the class exists already, which is usually not what was desired.

[edit] Declarations

The following things are available from the startup of the compiled binary:

  • Class declarations
  • Function declarations
  • Constants created with define() with a name and value easily determined at compile time

It's not possible to put code which you wish to execute at runtime in the file level of the same file that contains such declarations. Because the class or function already exists at startup, including the file leads to a duplicate definition error. Equally, you cannot define the same function or constant multiple times, even if the declarations are in multiple files. Wrapping the declaration in something like

// api.php
define( 'MW_ENTRY_POINT', 'API' );
 
...
 
if( MW_ENTRY_POINT == 'API' ) {
    function foo( $msg ){ ... }
}
 
// index.php
define( 'MW_ENTRY_POINT', 'MAIN' );
 
...
 
if( MW_ENTRY_POINT == 'MAIN' ) {
    function foo() { ... }
}

Will also not work, as the constant itself is doubly-defined.

Although all classes are available from startup, calling class_exists() on them will return false. This is a HipHop bug. To work around it, use MWInit::classExists() instead. This works by using the Reflection extension.

[edit] Differences compared with Zend PHP

  • Many extensions have only "stub" implementations, which apparently means that they have classes with the right methods, but the methods do nothing.
  • MySQL is the only supported DBMS.
  • Some functions have incomplete implementations:
    • error_log(): The message type is ignored, the string is just sent to the server log
    • method_exists(): The first parameter must be an object. Checking for static methods is not possible.
  • Most php.ini settings are gone. ini_get() and ini_set() only work for a few selected settings:
    • error_reporting
    • memory_limit
    • max_execution_time
    • hphp.build_id
    • arg_separator.output
    • upload_max_filesize
    • log_errors
    • error_log
    • notice_frequency
    • warning_frequency
    • include_path

Some other differences are listed in the inconsistencies file in the HipHop source.

[edit] To do

These tasks are available for anyone to work on:

  • Output compression is broken for large pages. Binary garbage is displayed. Isolate and report upstream.
  • Preview is broken, the server aborts when $wgParser->parse() is called from EditPage::getPreviewText(). Isolate and report upstream.
  • Make the PHPUnit tests work.
  • Test all core special pages and other core features.
  • Fix any extensions that you are interested in.
  • Fix the notices and warnings that HipHop generates at runtime, as far as possible.
  • Benchmarking & profiling:
    • Benchmark the CPU usage of various kinds of requests, comparing HipHop with Zend.
    • Profile CPU usage in HipHop and identify targets for optimisation.
    • Maybe look at using xhprof
Personal tools
Namespaces

Variants
Actions
Navigation
Support
Download
Development
Communication
Print/export
Toolbox