News for hackers. Stuff that matters.
Re:Show HN: FrankenPHP, an app server for PHP written in Go by mst on Saturday October 15, 2022 @07:01AM (#33213698)
Re (1) how feasible would it be to basically teach the PHP VM the equivalent of fork() so you can do all the booting once but still have a fresh copy of the end result on each request?

I mean, it's not going to be as cheap as getting the thing to actually run in a loop, but it might be enough cheaper than the booting process to be worthwhile.

Re:Show HN: FrankenPHP, an app server for PHP written in Go by bdg on Saturday October 15, 2022 @10:57AM (#33215399)
It's a cool idea but I haven't explored this in detail so I don't have a good answer. I haven't touched PHP in 2 years but they have a new feature which might achieve some of those design goals you mentioned:

https://www.php.net/manual/en/opcache.preloading.php

> preload.php is an arbitrary file that will run once at server startup (PHP-FPM, mod_php, etc.) and load code into persistent memory.

It's interesting to me, because in a big ecomm framework we were getting 80ms PHP page loads, with something like preload it could probably be moved down to 25 or 30ms.

Re:Show HN: FrankenPHP, an app server for PHP written in Go by eyberg on Monday October 24, 2022 @06:44PM (#33323630)
This is one of the things FrankenPHP is dealing with (w/out fork).

The big 'gotcha' here is that the heap is typically shared amongst threads in a process and that's where globals tend to live. However, you could make a heap per thread (which is kind of how some implementations of isolates work). You lose a bit of perf by doing this but it does deal with the global stomping problem.

We've (NanoVMs) looked at this a few times. It can be done but as bdg mentioned most frameworks expect state to be in a completely clear so the real challenge is that you have to go in and deal with each framework itself (for instance using WP as an example).

Anyways, I thought FrankenPHP was pretty cool so went ahead and package it up for Nanos: https://repo.ops.city/v2/packages/eyberg/frankenphp/0.0.1/x8... .

If you had a php framework that wasn't so dependent on global state you could definitely make something way more performant.

In general scripting languages and their usage of global state is a recurring concurrency issue but I'm hopeful that the isolate pattern will catch on in other languages to help alleviate it.