phpv8 / v8js

V8 Javascript Engine for PHP — This PHP extension embeds the Google V8 Javascript Engine
http://pecl.php.net/package/v8js
MIT License
1.83k stars 200 forks source link

Segmentation fault when constructing V8Js #153

Closed TomCaserta closed 9 years ago

TomCaserta commented 9 years ago

Hi whenever I attempt to create an instance of V8Js using new V8Js();

PHP segfaults with no error message. I turned on xdebug to figure out what was going on and this was the result:

    TRACE START [2015-08-06 08:40:21]
        0.0001     221416   -> {main}() Command line code:0
        0.0001     221968     -> V8Js->__construct() Command line code:1

From the command:

    php -d xdebug.auto_trace=ON -d xdebug.trace_output_dir=traces/ -r "new V8Js();";

My PHP info on V8Js looks like the following:

     v8js
     V8 Javascript Engine   enabled
     V8 Engine Compiled Version 4.6.0
     V8 Engine Linked Version   4.6.0 (candidate)
     Version    0.2.1
     Directive  Local Value Master Value
     v8js.flags no value    no value
     v8js.use_array_access  0   0
     v8js.use_date  0   0

Should the version be 0.2.1 or is that unrelated to the actual version of the extension. I compiled it only yesterday and previously had an older version of the extension working correctly on my site.

Output of php -v:

    PHP 5.6.10-1+deb.sury.org~trusty+1 (cli)
    Copyright (c) 1997-2015 The PHP Group
    Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
        with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies
        with Xdebug v2.3.2, Copyright (c) 2002-2015, by Derick Rethans
        with blackfire v0.24.1, https://blackfire.io/, by SensioLabs

Is there anything I can do about this issue except downgrade to the previous version that was working? Is there any other information that you require?

Here is a link to my full phpinfo: http://pastebin.com/raw.php?i=Sw82J4vi

TomCaserta commented 9 years ago

Aha just looking this looks like this may have been addressed in #152, will attempt one of the resolutions mentioned in there now.

TomCaserta commented 9 years ago

Ok after waiting an hour to finish compiling, nope, doesnt appear to have fixed the issue by adding the snapshot=off to the make command.

Heres the console output of the build: http://pastebin.com/raw.php?i=HB4yX18N

stesie commented 9 years ago

Err, the provided console output tells that the test suite did pass the test, so V8Js is working. Maybe the previously compiled version is around somewhere and it's actually loading that one?

There also is that strange message fatal: destination path 'v8js' already exists and is not an empty directory. the output. Depends on what the ran script is, whether that's a critical one. Just in case ...

stesie commented 9 years ago

@TomCaserta ping

Did that solve the problem you reported? Or doesn't it still work for you?

TomCaserta commented 9 years ago

Sorry was away for the weekend, I'm not entirely sure the path v8js existing would be a issue of which would cause it to not work (maybe, really do not know). I believe I have deleted all traces of v8js on my system and then recompiled, that fatal error did not occur when building it this time.

Thing is, it is still giving me a segmentation fault, I must have missed some reference to an older version of v8js somewhere but I cant figure out where.

Here is the build script I used:

#!/bin/bash -eux

apt-get install chrpath

cd /tmp

git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
export PATH=`pwd`/depot_tools:"$PATH"

fetch v8
cd v8

make native snapshot=off library=shared -j8

chrpath -r '$ORIGIN' out/native/lib.target/libv8.so

sudo mkdir -p /tmp/v8-install/lib /tmp/v8-install/include
sudo cp out/native/lib.target/lib*.so /tmp/v8-install/lib/
sudo cp -R include/* /tmp/v8-install/include
echo -e "create /tmp/v8-install/lib/libv8_libplatform.a\naddlib out/native/obj.target/tools/gyp/libv8_libplatform.a\nsave\nend" | sudo ar -M

cd /tmp
git clone https://github.com/preillyme/v8js.git
cd v8js
phpize
./configure --with-v8js=/tmp/v8-install
make
make test
sudo make install

echo "extension=v8js.so" > /etc/php5/mods-available/v8js.ini
ln -s /etc/php5/mods-available/v8js.ini /etc/php5/cli/conf.d/20-v8js.ini

service php5-fpm restart
service nginx restart
TomCaserta commented 9 years ago

Oh wow, okay sorted it. So originally there was definitely some sort of issue with the extension I compiled, which then caused me to use Xdebug.

Now I decided to not use xdebug and just try running it normally after I compiled it with the snapshot=off. It didn't segfault this time, I double checked it was working by printing something via javascript and that all worked correctly. So at this point I know that everything was correct in the config files and it was loading the correct extension. And thats when I realised that when I was issuing the php5-fpm restart command it wasnt actually restarting due to a bug on ubuntu that is laid out here:

http://stackoverflow.com/questions/19998526/ubuntu-php5-fpm-throws-unknown-instance-on-reload

After applying that fix. Killing php5-fpm and starting it up again, everything works correctly now which is great.

Thank you for your help @stesie.