5

I'm writing an C++ extension (dynamic load) for HHVM. I followed the instructions on this page: https://github.com/facebook/hhvm/wiki/Extension-API

which links to an example in: https://github.com/hhvm/extension-example

I compiled hhvm on Ubuntu 14.04 which took nearly 2 hours. Then I also compiled the example extension.

My question is, how to load it?

The information on the internet seems to be out-of-date or inconsistent. Anyway, I first tried to create /etc/hhvm/config.hdf with these lines:

DynamicExtensions {
  example = /path/to/example.so
}

Nothing happened. And then I saw this: From: http:// hhvm.com/blog/4349/hhvm-3-0-0

We are moving from .hdf config files to .ini. The default one lives in /etc/hhvm/php.ini. We don’t support all the old options yet, so you can still use config.hdf for now, but be ready for it to die in the next release. All of your favorite options will go from Foo { BarBaz = True } to hhvm.foo.bar_baz = true.

OK, then I tried to put lines in /etc/hhvm/php.ini or /etc/hhvm/server.ini instead of .hdf

hhvm.dynamic_extensions.example = /path/to/example.so

But with no luck, nothing worked. I need more info/docs.

So, is there anyone know what happen? or if the HHVM team from Facebook see this post, could you please help me?

Josh Watzman
  • 7,060
  • 1
  • 18
  • 26
kchkg
  • 147
  • 3
  • 13
  • Update: I can load the module, but can't find the example_sum() function. Fatal error: Call to undefined function example_sum() in /home/ubuntu/example/test.php on line 7 – kchkg May 26 '14 at 16:56
  • why did you compile hhvm ? Do you have problem to run hhvm or you have successfully installed it ?Do you have problem load an extension? (sorry but i did not understand your problem ) – Themis Beris May 26 '14 at 17:52
  • 1
    @ThemisBeris you currently need to compile HHVM yourself to get `hphpize` and the necessary header and cmake files. –  May 26 '14 at 22:17
  • 1
    yes, I had to compile hhvm because when I tried to run hphpize (cmd not found...oops) and I actually did that on AWS cost me $0.132 per Hour LOL – kchkg May 27 '14 at 02:19
  • you can install `hhvm-dev` if you dont want to compile it, it'll allow you to run hphpize – Steel Brain Aug 02 '14 at 18:02

1 Answers1

7

I see that you've managed to get it to load, so I'll just focus on not being able to find the function.

Shortly after the release of HHVM 3.0, the way that PHP files are loaded from extensions changed. Basically, the first four characters of the name of the file are stripped when embedding it, since it's expected to be ext_name.php. The example extension hadn't been updated for this change until last night.

The change is rather simple. Just rename example.php to ext_example.php and, in config.cmake change HHVM_SYSTEMLIB(example example.php) to HHVM_SYSTEMLIB(example ext_example.php) then re-run cmake . && make.

You can see the committed change (which does exactly this) here

  • actually I still haven't solved my problem completely. you said I managed to get it to load, yes and no. yes, when I run hhvm -c config.hdf test.php, but my FastCGI setup is not loading the extension, and /etc/hhvm/config.hdf doesn't exist, so I created one, still not working. So I guess hhvm team changed config file to /etc/hhvm/server.ini? I read the code in extension.cpp, it seems hhvm still reads .hdf config, but where is it? – kchkg May 27 '14 at 07:11
  • 1
    @KenjiChan You can pass multiple config files to HHVM. If you edit `/etc/default/hhvm` file, you can set `ADDITIONAL_ARGS` to `-c /etc/hhvm/config.hdf` and then it will be used as well as `/etc/hhvm/server.ini` –  May 27 '14 at 10:07
  • while (true) print("Thanks!\n"); – kchkg May 27 '14 at 12:25
  • Update: I found that I have 2 versions(3.0.1, 3.2.0 dev) of hhvm installed, and I have to fix my startup script to use the newer version. So I tried to uninstall using "apt-get remove hhvm", but it also remove the startup script, which seems to be correct. Now, do I have to create/copy the script myself or to do something like "sudo make install_startup_script" in the source folder? – kchkg May 27 '14 at 18:21
  • 1
    A simple `make install` might do it, otherwise all the scripts are available in the [packaging](https://github.com/hhvm/packaging/blob/master/hhvm/deb/skeleton/) repository, with the init.d one available [here](https://github.com/hhvm/packaging/blob/master/hhvm/deb/skeleton/etc/init.d/hhvm). –  May 28 '14 at 06:52