can't load HHVM extension (dynamic)
Asked Answered
A

1

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?

Archy answered 26/5, 2014 at 10:33 Comment(5)
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 7Archy
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 )Hypabyssal
@ThemisBeris you currently need to compile HHVM yourself to get hphpize and the necessary header and cmake files.Rora
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 LOLArchy
you can install hhvm-dev if you dont want to compile it, it'll allow you to run hphpizeBalkan
R
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

Rora answered 26/5, 2014 at 22:16 Comment(5)
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?Archy
@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.iniRora
while (true) print("Thanks!\n");Archy
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?Archy
A simple make install might do it, otherwise all the scripts are available in the packaging repository, with the init.d one available here.Rora

© 2022 - 2024 — McMap. All rights reserved.