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.84k stars 200 forks source link

PHP-fpm and cli #377

Closed bobahvas closed 3 years ago

bobahvas commented 6 years ago

When I run v8js from cli - it works well. But when I try to execute the same code via php-fpm I get an error like 'Class 'V8Js' not found'

Could someone explain what I missed? My code is very simple:

<?php
$v8 = new V8Js(); 
echo $v8->executeString('let hello = "Hello, "; let world = "World"; hello + world; ');
bjorno43 commented 6 years ago

Most likely your webserver is using seperate php.ini files for each host. Just create a php file with:

<?php
phpinfo();
?>

And check which one php-fpm is using. Then just edit that file and add extension=v8js.so to it. Restart PHP and it should work.

bobahvas commented 6 years ago

@bjorno43 thank you for your reply, but my situation is not so easy

PHP FPM loads all ini files in /etc/php.d by default. Inside this directory I have v8js.ini that contains the following text extension=v8js.so. In the directory /usr/lib64/php/modules I have v8js.so

If I run from cli the following command, I can see output like

php ./phpinfo.php | grep v8
/etc/php.d/v8js.ini,
v8js
v8js.flags => no value => no value
v8js.icudtl_dat_path => no value => no value
v8js.use_array_access => 0 => 0
v8js.use_date => 0 => 0

And var_dump(extension_loaded('v8js')); return true.

PHP FPM version of phpinfo contains /etc/php.d/v8js.ini

Additional .ini files parsed | /etc/php.d/bz2.ini, /etc/php.d/calendar.ini, /etc/php.d/ctype.ini, /etc/php.d/curl.ini, /etc/php.d/dom.ini, /etc/php.d/exif.ini, /etc/php.d/fileinfo.ini, /etc/php.d/ftp.ini, /etc/php.d/gettext.ini, /etc/php.d/gmp.ini, /etc/php.d/iconv.ini, /etc/php.d/igbinary.ini, /etc/php.d/imagick.ini, /etc/php.d/json.ini, /etc/php.d/mbstring.ini, /etc/php.d/mysqli.ini, /etc/php.d/pdo.ini, /etc/php.d/pdo_mysql.ini, /etc/php.d/pdo_sqlite.ini, /etc/php.d/phar.ini, /etc/php.d/posix.ini, /etc/php.d/shmop.ini, /etc/php.d/simplexml.ini, /etc/php.d/sockets.ini, /etc/php.d/sqlite3.ini, /etc/php.d/sysvmsg.ini, /etc/php.d/sysvsem.ini, /etc/php.d/sysvshm.ini, /etc/php.d/tokenizer.ini, /etc/php.d/v8js.ini, /etc/php.d/xdebug.ini, /etc/php.d/xml.ini, /etc/php.d/xml_wddx.ini, /etc/php.d/xmlreader.ini, /etc/php.d/xmlwriter.ini, /etc/php.d/xsl.ini, /etc/php.d/z-memcached.ini, /etc/php.d/zip.ini

However var_dump(extension_loaded('v8js')); returns false.

P/S/ Rename of ini file helped. Why!?!?

nozreh commented 6 years ago

@bobahvas what do you mean by rename of ini file? I'm also having this error in my Laravel app

nullwriter commented 3 years ago

So did anyone resolve this? having this same issue

bobahvas commented 3 years ago

@nullwriter I didn't run this extension for several years. As I remember, in my case v8js.ini file wasn't parsed, so I simply renamed this v8js.ini to something different like 090-v8js.ini. I guess in my webserver I had a specific pattern for configs.

But now based on my experience I can recommend you to use node.js for server-side rendering. If you want to have a good solution - you shouldn't mix PHP and js =)