Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: embed PHP thanks to FrankenPHP #216

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

dunglas
Copy link

@dunglas dunglas commented Nov 12, 2022

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

@@ -31,6 +31,7 @@ import (
"path/filepath"
"syscall"

"github.com/dunglas/frankenphp"
Copy link
Contributor

@shyim shyim Nov 13, 2022

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
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
Copy link
Contributor

Kocal commented Nov 13, 2022

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

@dunglas
Copy link
Author

dunglas commented Nov 13, 2022

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

@kevinpapst
Copy link

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

@stof
Copy link

stof commented Oct 26, 2023

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
Contributor

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
Contributor

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
Copy link
Author

dunglas commented Nov 20, 2023

@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
Copy link
Author

dunglas commented Nov 20, 2023

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.

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.

None yet

6 participants