Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[WIP] an approach to embedding main() into sapi/embed from php code #19707

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

Draft
krakjoe wants to merge 1 commit into php:master
base: master
Choose a base branch
Loading
from krakjoe:krakjoe/embed-xxd

Conversation

Copy link
Member

@krakjoe krakjoe commented Sep 4, 2025
edited
Loading

This is a possible approach to deploying embed with some php code embedded for main(), we don't have to require any special deps, or really make significant changes.

Options:

  • --with-embed-main takes path to php/phar file
  • --with-embed-link takes path for symlink creation (phar requires a symlink with the same name as the archive when it was created)

Possible improvements:

  • sigint (cleanup properly)
  • determine link name automagically
  • add ability to set hardcoded ini
  • do less nasty things in config.m4, formalize in makefile
  • set name of executable

Tested widely enough to make sure phar archives work, obvious this is very nix focused, I've no idea how to do this in a windows friendly way.

Example:

--with-embed-main=/path/to/pie.phar --with-embed-link=pie.phar creates:

krakjoe@fiji:/opt/src/php-src$ /opt/bin/php-embed-main build apcu/apcu
#!/usr/bin/env php
🥧 PHP Installer for Extensions (PIE) 1.2.0, from The PHP Foundation
You are running PHP 8.5.0-dev
Target PHP installation: 8.5.0-dev ts, on Linux/OSX/etc x86_64 (from /opt/bin/php)
Found package: apcu/apcu:v5.1.27 which provides ext-apcu
Extracted apcu/apcu:v5.1.27 source to: /home/krakjoe/.config/pie/php8.5_36ea40acb359a0ef916e847e11dafbd9/vendor/apcu/apcu
phpize complete.
Configure complete.
Running make without parallelization - try providing -jN to PIE where N is the number of cores you have.
Build complete: /home/krakjoe/.config/pie/php8.5_36ea40acb359a0ef916e847e11dafbd9/vendor/apcu/apcu/modules/apcu.so

\$(PHP_GLOBAL_OBJS) \$(PHP_SAPI_OBJS) \$(EXTRA_LIBS) \$(ZEND_EXTRA_LIBS) \
-o \$(INSTALL_ROOT)\$(bindir)/php-embed-main"
if test "$PHP_EMBED_LINK" != "no"; then
AC_DEFINE_UNQUOTED([PHP_EMBED_LINK], ["$PHP_EMBED_LINK"], [PHP_EMBED_LINK])
Copy link
Member Author

@krakjoe krakjoe Sep 6, 2025

Choose a reason for hiding this comment

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

if this is yes/empty we could use basename of PHP_EMBED_MAIN, this will normally be correct.

@@ -244,7 +247,6 @@ EMBED_SAPI_API int php_embed_init(int argc, char **argv)

SG(headers_sent) = 1;
SG(request_info).no_headers = 1;
php_register_variable("PHP_SELF", "-", NULL);
Copy link
Member Author

@krakjoe krakjoe Sep 6, 2025

Choose a reason for hiding this comment

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

I'm not exactly sure why this is here, it doesn't look correct ... I moved to register_server_variables because that's idiomatic, and allows consumers to control this behavior appropriately


static php_stream *s_in_process = NULL;

static int php_embed_main_streams(void) {
Copy link
Member Author

@krakjoe krakjoe Sep 6, 2025
edited
Loading

Choose a reason for hiding this comment

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

lifted from cli, possibly this should be exported API function in main ...

Copy link

This is essentially the same as compiling embed=static followed by compiling and linking a simple C program that executes php code against the produced libphp.a, right?

https://github.com/easysoft/phpmicro goes for a different approach to provide the same functionality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /