joehoyle / php-quickjs

PHP bindings for QuickJS
3 stars 0 forks source link

Conclusions #1

Open dbalabka opened 2 years ago

dbalabka commented 2 years ago

Hello,

I'm looking for a possibility to integrate QuickJS into PHP using FFI. Could you please share your thoughts about how feasible is to use QuickJS in PHP via FFI? Also, it is very interesting to hear about your initial goals to perform such an experiment. 😃

Thanks in advance.

joehoyle commented 2 years ago

Hi @dbalabka,

I don't think I got far with this, before pursuing another option. The idea was to use FFI, so users would not need to install a PHP extension; however I quickly hit some walls (which I can't remember, it's been some time!).

Since then I've been working on https://github.com/joehoyle/php-v8js/ )which is a PHP extension) to embed V8.

dbalabka commented 2 years ago

@joehoyle, thanks for quick reply. I've already reviewed your PHP extension for V8 which looks very promising and interesting because of Rust application. Are you looking for a way to perform SSR on PHP side?

joehoyle commented 2 years ago

SSR in PHP is certainly useful, and that's where we started. Typically though doing this is V8 (as opposed to Node) can be tricky-- you have to shim bits and pieces so react-dom-ssr will work etc. It mostly works, but some edge cases can catch developers out.

The more interesting usecases I think are around running sandboxed JavaScript, and providing that to CMS power users to be able to script business logic. Think something like iOS Shortcuts where you can write JavaScript. I've been experimenting with some kind of automations system (similar to the new Slack https://api.slack.com/future/tools automation tools). Also, as a system for extensibility for developers, being able to run addons to the core PHP system that are sandboxed and resource constrained has security and stability advantages. Something like running Laraval packages in a JavaScript sandbox.

dbalabka commented 2 years ago

@joehoyle, so my initial idea was to implement simple SSR because running separate NodeJS instances is quite expensive and complicated to integrate into existing applications. I found that QuickJS became quite popular. Currently, it is a way to execute JS inside WebAssebmly and it is a reason why QuickJS is so small and does not have a JIT compiler. As a result, I would like to replace Twig templates with React/Vue components to reuse them on both sides. BTW there is a bit outdated prototype using Rust with QuickJs that performs SSR: https://github.com/galvez/fast-vue-ssr

Sandboxing Javascript for plugins sounds very promising.