hhvm Hack その4/CakePHPを動かしてみる①
環境 CentOS6.5 hhvm3.2.0 CakePHP 2.5.4
hhvm 上でcakephpを動かしてみます。
以下を参照しています。
hphpとかは今は
hhvm -hphp
になってます。
Running CakePHP using the Facebook's HipHop compiler :: The Bakery: Everything CakePHP
HipHop Pluginを導入
hhvm用のPluginを作ってくれている方がいるので、それを使います。
設置
$ cd /var/www/hhvm/app/Plugin
$ git clone https://github.com/lorenzo/HipHop
bootstrap.phpでHipHop Pluginを読み込みます。
$ cd /var/www/hhvm/app/Config/ $ cp -a bootstrap.php bootstrap.php.ORI $ vim bootstarp.php
$ diff -u bootstrap.php.ORI bootstrap.php --- bootstrap.php.ORI 2014-09-02 11:05:27.000000000 +0900 +++ bootstrap.php 2014-09-24 08:40:18.812375455 +0900 @@ -106,3 +106,6 @@ 'types' => array('warning', 'error', 'critical', 'alert', 'emergency'), 'file' => 'error', )); + +// Plugin +CakePlugin::load('HipHop');
config.hdfの設定
hhvm起動のconfig.hdfはPluginの中のものを使います。
$ cd /var/www/hhvm/app/Plugin/HipHop/Config/ $ cp -a config.hdf config.hdf.ORI $ vim config.hdf
$ diff -u config.hdf.ORI config.hdf --- config.hdf.ORI 2014-09-24 08:37:48.835375495 +0900 +++ config.hdf 2014-09-24 09:01:52.554375110 +0900 @@ -1,13 +1,11 @@ -#include "[path to hiphop build]/bin/mime.hdf" - Server { Port = 80 - SourceRoot = [path to your ROOT folder (the one containing app and lib/Cake)] + SourceRoot = /var/www/hhvm } VirtualHost { * { - Prefix = [virtual host name (example.com)] + Prefix = hiphop.local RewriteRules { * { pattern = ^(.*)$ @@ -29,3 +27,14 @@ } } +Log { + Level = Error + UseLogFile = true + File = /var/log/hhvm/error.log + Access { + * { + File = /var/log/hhvm/access.log + Format = %h %l %u %t \"%r\" %>s %b + } + } +}
とりあえず、ここでindexは一応動きました。
http://hiphop.local/
クラスのマッピング
hhvmは動的な読み込みに対応してくれないため、クラスをマッピングして読み込ませる必要があります。
HipHop does not implement any kind of automatic class loader, so we need to provide a complete list of classes to be used in your application, this is a big difference between the hphpi interpreter and the compiler. Your CakePHP application will run just fin in the interpreter, but it won't after compiling if you are unable to tell it where your classes are. For this purpose, the plugin bundles a shell that needs to be executed before compiling your code:
Running CakePHP using the Facebook's HipHop compiler :: The Bakery: Everything CakePHP
$ cd /var/www/hhvm $ app/Plugin/HipHop/Config/scripts/generate_list $ hhvm --hphp --target hhbc --input-list files.list -k1 -l3 $ app/Plugin/HipHop/Config/scripts/fixconstants
本来なら、ここで生成された /tmp/hphp_* で make をすれば専用の hhvm 実行ファイルが作成され、それを-m daemonで動かしますが、エラーが出てます。
エラーは/tmp/hphp_*/CodeError.js に出力されます。
ざっと見ると、
PHPIncludeFileNotFound
UseUndeclaredGlobalVariable
UseUndeclaredConstant
UnknownClass
UnknownFunction
DeclaredConstantTwice
TooManyArgument
BadArgumentType
UseVoidReturn
BadPassByReference
これはhhvmがphpに比べていろんなところで厳しい制限があるようですね。
例えば UseUndeclaredGlobalVariable はhtmlでを使用しているからですね。
さてどうしましょうか。
直すしかないんですが引っかかってるのが、全部coreの部分ですね。
ちょっと調べる必要があるので、残りは今度で。
==追記 2014/09/29==
結論、難しいですね。マッピング時のエラーで無くしてもCakePHP自体が動かない。
全部完全に直すのは相当苦労です。
必要に迫られない限りは無視かな。
HHVM
を見ると、CakePHP3は対応しそうですね。
そのときにまた試してみましょう。
でも、とりあえず何か動かしたいので、ちょっと興味のあったcodeigniterを使ってみようと思います。