Skip to content

feat: embed PHP thanks to FrankenPHP#216

Draft
dunglas wants to merge 2 commits into
symfony-cli:mainfrom
dunglas:feat/frankenphp
Draft

feat: embed PHP thanks to FrankenPHP#216
dunglas wants to merge 2 commits into
symfony-cli:mainfrom
dunglas:feat/frankenphp

Conversation

@dunglas

@dunglas dunglas commented Nov 12, 2022

Copy link
Copy Markdown

Thanks to FrankenPHP, it's possible to embed PHP directly in the Symfony Local Web Server.
That's what this patch does!

symfony server:start --frankenphp

image

Basically, that means that you don't need a local installation of PHP anymore.

The code is working, but the build chain isn't ready. We'll have to build libphp in the CI and statically link the produced binary against it.

Support for other PHP SAPI is still included and FrankenPHP is currently opt-in.

Current limitations are:

Needs symfony-cli/phpstore#3

"path/filepath"
"syscall"

"github.com/dunglas/frankenphp"

@shyim shyim Nov 13, 2022

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to have here a go build tag? Frankenphp uses a lot of cgo which would break the release ci pipeline as it's not possible to cross compile anymore 🤔

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could do that, but first I'll try to have to build a release pipeline supporting all current targets (they are supported by PHP, and we can use Docker to cross-compile).

@Kocal

Kocal commented Nov 13, 2022

Copy link
Copy Markdown
Contributor

That's a great initiative, but would it support the .php-version feature?

@dunglas

dunglas commented Nov 13, 2022

Copy link
Copy Markdown
Author

@Kocal not yet. FrankenPHP is only compatible with PHP 8.2+.

@kevinpapst

Copy link
Copy Markdown

How much will that increase the size of the Symfony binary? Why does one tool have to solve all issues?

@stof

stof commented Oct 26, 2023

Copy link
Copy Markdown

As we still need to have a local PHP setup for the CLI (a Symfony project requires a PHP CLI, at least to run composer), is there any benefit for that ? This only saves installing the php-fpm package locally in addition to all the other packages that are shared with the php-cli one.

@tucksaun

Copy link
Copy Markdown
Member

How much will that increase the size of the Symfony binary ?

I would say about 100mb (rough estimate)

As we still need to have a local PHP setup for the CLI (a Symfony project requires a PHP CLI, at least to run composer), is there any benefit for that ? This only saves installing the php-fpm package locally in addition to all the other packages that are shared with the php-cli one.

I agree.

Also we lose the multi version support and we don't expose the configurability of Franken so no big win here I think.

@tucksaun

Copy link
Copy Markdown
Member

Maybe we can do something by working wi Go plugins to have this optional?
or reuse the fact we can talk HTTP or CGI with the backend server?

@dunglas

dunglas commented Nov 20, 2023

Copy link
Copy Markdown
Author

@stof, FrankenPHP now natively supports CLI scripts too. The Caddy plugin already has this feature, this should be easy to add to Symfony CLI.

@dunglas

dunglas commented Nov 20, 2023

Copy link
Copy Markdown
Author

Also, FrankenPHP supports libphp.so in addition to static builds, so it should be possible to distribute (or , better, download on demand) different PHP versions, for instance from the PHP Builder project (also used by setup-php), which provides dynamic libphp builds compatible with FrankenPHP. This approach would also have the benefit of not increasing much the binary size.

@tibobaldwin

Copy link
Copy Markdown

Hi,
Is this feature still current?
Should we rather go directly through the FrankenPHP website?
In any case, it is true that this will facilitate the integration of FrankenPHP by going through Symfony CLI.
Thank you!

@dunglas

dunglas commented Nov 26, 2025

Copy link
Copy Markdown
Author

In my opinion, the best option would be to do in the other way: extract the Symfony-specific features provided by symfony-cli in a standalone Go library and provide it as a plugin for FrankenPHP.

cc @fabpot @tucksaun

@tucksaun

tucksaun commented Nov 26, 2025

Copy link
Copy Markdown
Member

I'm not sure this would add much value doing it this way (because if I picture it correctly most features would not make sense in a Franken context or be a duplicate of Franken's).
But because there's almost nothing in main for the Symfony CLI, I believe one could already do that if they want to invest the effort to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

7 participants