Skip to content

Add chapter on embedding PHP #136

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

Open
cubiclesoft opened this issue Nov 10, 2022 · 2 comments
Open

Add chapter on embedding PHP #136

cubiclesoft opened this issue Nov 10, 2022 · 2 comments

Comments

@cubiclesoft
Copy link

There is almost no documentation on the Internet on how to compile and use the PHP embed SAPI. The only "official" source is a very old book by Sara Golemon entitled "Extending and Embedding PHP." There's a macro called PHP_EMBED_START_BLOCK that appears to kick off the linkage between C/C++ code and the PHP embed SAPI. This is the first complete code sample that I found by searching for that macro:

https://stackoverflow.com/questions/73345686/store-output-of-php-execute-script

@Girgias
Copy link
Collaborator

Girgias commented Nov 10, 2022

I know @dunglas had started to write a bit because he hit the same issue while working on FrankenPHP

@SammyK
Copy link
Collaborator

SammyK commented Nov 10, 2022

The embed SAPI readme has basic info on how to compile and run the SAPI.

The embed SAPI isn't very useful on its own. It only allows setting up a full PHP startup + request cycle without the ability to take control of the individual request cycle within the startup cycle. It really serves as a bare-bones SAPI that is a good starting point for a fork.

Example: the unit tests for the Datadog PHP tracer are run with Tea SAPI which is a fork of embed.

Adding a chapter to the internals book on compiling/forking embed is a good idea. 👍

(Tangentially related; libphp is only created when PHP is compiled with --enable-embed which means if you fork embed, you'll need to enable embed to gain access to the shared lib. IMO we should add a way to create the shared lib without explicitly enabling embed so that we don't hit the too-many-SAPIs limit at compile time when you have a custom SAPI that you'd like to run alongside several other in-tree ones. But I only dream. 😄)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants