# [RFC] Extension Prepend Files

- Thread: https://externals.io/message/80142
- Original archive: https://news-web.php.net/php.internals/80142
- Started by Benjamin Eberlei on 2015-01-04T11:52:17+00:00
- Messages: 66
- Page 1 of 3: messages 1 to 25 (25 per page, add `?page=N` to the URL)
- Next page: https://externals.io/message/80142.md?page=2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #80142 — Benjamin Eberlei — 2015-01-04T11:52:17+00:00

URL: https://externals.io/message/80142#80142

Hey everyone,

I want to open discussion on my RFC to strengthen the ability of extensions
to provide functionality to developers in both C **and** PHP code.

For this extensions can add PHP files to a list of "prepend files" that are
part of every request execution exactly the same way the INI
auto_prepend_file functionality works:

https://wiki.php.net/rfc/extension_prepend_files

I propose implementation details in the RFC, but they are completely up to
discussion. I am even sure there is probably a better way than what I
proposed, because I am not familiar with the code.

greetings
Benjamin

---

## #80143 — reeze — 2015-01-04T12:33:52+00:00

URL: https://externals.io/message/80142#80143 · In reply to: #80142

I like the idea, I have implemented a util [1] to help writing extensions
with PHP, I try the approach HHVM adopted by embedding PHP scripts to the
binary file of extension, maybe it is what you want.  I do like it been
supported in core. I would like to implement the RFC if others like it.

---
[1] https://github.com/reeze/php-ext-embed




> Hey everyone,
>
> I want to open discussion on my RFC to strengthen the ability of extensions
> to provide functionality to developers in both C **and** PHP code.
>
> For this extensions can add PHP files to a list of "prepend files" that are
> part of every request execution exactly the same way the INI
> auto_prepend_file functionality works:
>
> https://wiki.php.net/rfc/extension_prepend_files
>
> I propose implementation details in the RFC, but they are completely up to
> discussion. I am even sure there is probably a better way than what I
> proposed, because I am not familiar with the code.
>
> greetings
> Benjamin

---

## #80144 — francois@tekwire.net — 2015-01-04T12:36:52+00:00

URL: https://externals.io/message/80142#80144 · In reply to: #80142

> De : Benjamin Eberlei [mailto:kontakt@beberlei.de]
> I want to open discussion on my RFC to strengthen the ability of extensions
> to provide functionality to developers in both C **and** PHP code.
> 
> For this extensions can add PHP files to a list of "prepend files" that are
> part of every request execution exactly the same way the INI
> auto_prepend_file functionality works:
> 
> https://wiki.php.net/rfc/extension_prepend_files
> 
> I propose implementation details in the RFC, but they are completely up to
> discussion. I am even sure there is probably a better way than what I
> proposed, because I am not familiar with the code.

Can you please develop the API changes in your RFC ? You're talking about changes in zend_execute_scripts(), a new zend_execute_script() function (but the name in the prototype is wrong), then php_execute_scripts()...

Where are the file handles coming from ? Does it mean that the files to prepend will be kept open ?

Do you register paths to prepend, or will the scripts be loaded in memory during MINIT ?

How will these files be cached by opcode caches (mandatory for such a feature) ?

And, finally, how can an extension determine where a given PHP script it requires has been installed ? It makes sense in php.ini because it is under control of the final user. But an extension is just a C library, installed anywhere or bundled in the PHP executable. Would it compute the script paths from PHP installation paths ?

Actually, I don't see how it would work with PHP scripts which would remain separate from the extension code. What I would imagine for such a feature, would be PHP code embedded in the extension as a memory buffer, registered during MINIT, and then executed at each RINIT. This would probably require a stream wrapper because the opcode cache would require paths for this code. We can also concatenate the scripts but we still need a virtual path. The stream wrapper would just be simpler to implement.

Regards

François

---

## #80145 — Benjamin Eberlei — 2015-01-04T13:00:52+00:00

URL: https://externals.io/message/80142#80145 · In reply to: #80144

On Sun, Jan 4, 2015 at 1:36 PM, François Laupretre <francois@tekwire.net>
wrote:

> > […]
> extensions
> > […]
> are
> > […]
> to
> > […]
>
> Can you please develop the API changes in your RFC ? You're talking about
> changes in zend_execute_scripts(), a new zend_execute_script() function
> (but the name in the prototype is wrong), then php_execute_scripts()...
>

Fixed the typo in zend_execute_script. The API of php_execute_scripts
doesnt change, only the implementation.


>
> Where are the file handles coming from ? Does it mean that the files to
> prepend will be kept open ?
>

File handles have existed before in php_execute_scripts, they were passed
via the va_list into zend_execute_scripts.

>
> Do you register paths to prepend, or will the scripts be loaded in memory
> during MINIT ?
>

You register file paths to prepend.

>
> How will these files be cached by opcode caches (mandatory for such a
> feature) ?
>

Files will be cached, because opcache hooks into zend_compile_file, which
is used downstream of zend_execute_scripts. That means the feature would
autoamtically use and work with opcache.

>
> And, finally, how can an extension determine where a given PHP script it
> requires has been installed ? It makes sense in php.ini because it is under
> control of the final user. But an extension is just a C library, installed
> anywhere or bundled in the PHP executable. Would it compute the script
> paths from PHP installation paths ?
>

Files must be either in the PHP include path, or via absolute path, for
example by putting them right next to the shared object (.so) files and
using the extension_dir path inside the code, see the following for an
example (a hacked approach):
https://github.com/QafooLabs/php-profiler-extension/blob/master/qafooprofiler.c#L744


> Actually, I don't see how it would work with PHP scripts which would
> remain separate from the extension code. What I would imagine for such a
> feature, would be PHP code embedded in the extension as a memory buffer,
> registered during MINIT, and then executed at each RINIT. This would
> probably require a stream wrapper because the opcode cache would require
> paths for this code. We can also concatenate the scripts but we still need
> a virtual path. The stream wrapper would just be simpler to implement.
>

This uses the usual "require" functionality that you can call from PHP as
well. If the files are not found, then you get an error.

>
> Regards
>
> François

---

## #80146 — Benjamin Eberlei — 2015-01-04T13:02:48+00:00

URL: https://externals.io/message/80142#80146 · In reply to: #80143

Hey reeze,

This looks like a fantastic approach. Can you explain how you compile the
PHP code into the Shared Object? The README doesnt explain much.

greetings
Benjamin



> I like the idea, I have implemented a util [1] to help writing extensions
> with PHP, I try the approach HHVM adopted by embedding PHP scripts to the
> binary file of extension, maybe it is what you want.  I do like it been
> supported in core. I would like to implement the RFC if others like it.
>
> ---
> [1] https://github.com/reeze/php-ext-embed
>
>
> 
>
> > […]

---

## #80147 — reeze — 2015-01-04T13:11:03+00:00

URL: https://externals.io/message/80142#80147 · In reply to: #80146

Hi Benjanmin,
   I didn't try to cache opcode myself, I try it before, but I think it
should be done by opcaches (avoid duplication and opcache will optimize the
compiled opcode), so I use the method @François mentioned, I use a stream
wrapper to take advantage of opcaches. there is a problem opcache didn't
allow streams except `file://` and `phar://`, @François created a RFC to
support it [1], if that was accepted, it should work with full speed :)


--
[1] https://github.com/php/php-src/pull/976/files



> Hey reeze,
>
> This looks like a fantastic approach. Can you explain how you compile the
> PHP code into the Shared Object? The README doesnt explain much.
>
> greetings
> Benjamin
>
> 
>
> > […]

---

## #80174 — Pierre Joye — 2015-01-05T14:02:18+00:00

URL: https://externals.io/message/80142#80174 · In reply to: #80142

Hi,


>
> Hey everyone,
>
> I want to open discussion on my RFC to strengthen the ability of
extensions
> to provide functionality to developers in both C **and** PHP code.
>
> For this extensions can add PHP files to a list of "prepend files" that
are
> part of every request execution exactly the same way the INI
> auto_prepend_file functionality works:
>
> https://wiki.php.net/rfc/extension_prepend_files
>
> I propose implementation details in the RFC, but they are completely up to
> discussion. I am even sure there is probably a better way than what I
> proposed, because I am not familiar with the code.

I understand the idea however I wonder what are the gains for the user? On
any case the file has to be at the right place, etc.

Also as it is internals only, it could be nicer to expose the prepend
config using the existing directive with options like first, before, last
for the insert position.

While being at it, a similar feature can be added to auto prepend/append as
it can be very useful in user land as well.

Cheers,
Pierre

---

## #80175 — Benjamin Eberlei — 2015-01-05T15:41:13+00:00

URL: https://externals.io/message/80142#80175 · In reply to: #80174

> Hi,
>
> 
> > […]
> extensions
> > […]
> are
> > […]
> to
> > […]
>
> I understand the idea however I wonder what are the gains for the user? On
> any case the file has to be at the right place, etc.
>
The shared object file has to be at the right place as well.


> Also as it is internals only, it could be nicer to expose the prepend
> config using the existing directive with options like first, before, last
> for the insert position.
>
This assumes that we have dependencies between extensions, which we don't
have anyways. Now if extensions depend on each other the order is
important. I assume that the loading order is also the order that the MINIT
is called, which then would also put dependent php files in order.


> While being at it, a similar feature can be added to auto prepend/append
> as it can be very useful in user land as well.
>
Yes maybe, although I don't see the benefit for userland TBH, compared to
extensions. Extensions are about declaring functions/classes, prepend is
normally about actually "executing"/running code.

> Cheers,
> Pierre

---

## #80176 — Rowan Collins — 2015-01-05T16:11:00+00:00

URL: https://externals.io/message/80142#80176 · In reply to: #80145

Benjamin Eberlei wrote on 04/01/2015 13:00:
> Files must be either in the PHP include path, or via absolute path, for
> example by putting them right next to the shared object (.so) files and
> using the extension_dir path inside the code, see the following for an
> example (a hacked approach):
> https://github.com/QafooLabs/php-profiler-extension/blob/master/qafooprofiler.c#L744

Beware that anything that looks in a configurable or 
environment-dependent list of include directories has the potential to 
open up security holes - anyone who can change that setting, or who has 
write access to a directory with higher priority, can inject code in a 
very broad context. It can also lead to surprising side effects if a 
file with the same name is coincidentally placed into more than one 
directory in the search path.

I think if the intention is for extensions to ship these files directly, 
the registration mechanism should create an absolute path based either 
on a single configured directory, which distributors will set based on 
their installation paths, or on the directory containing the .so file 
being loaded.

Regards,
-- 
Rowan Collins
[IMSoP]

---

## #80177 — Julien Pauli — 2015-01-05T16:19:59+00:00

URL: https://externals.io/message/80142#80177 · In reply to: #80142

On Sun, Jan 4, 2015 at 12:52 PM, Benjamin Eberlei <kontakt@beberlei.de>
wrote:

> Hey everyone,
>
> I want to open discussion on my RFC to strengthen the ability of extensions
> to provide functionality to developers in both C **and** PHP code.
>
> For this extensions can add PHP files to a list of "prepend files" that are
> part of every request execution exactly the same way the INI
> auto_prepend_file functionality works:
>
> https://wiki.php.net/rfc/extension_prepend_files
>
> I propose implementation details in the RFC, but they are completely up to
> discussion. I am even sure there is probably a better way than what I
> proposed, because I am not familiar with the code.
>

Hello.

Can't this be already done somehow ? In RINIT stage obviously.
I don't understand why to change our API to add a feature we already can
use ?

Julien.P

---

## #80178 — Rowan Collins — 2015-01-05T16:26:23+00:00

URL: https://externals.io/message/80142#80178 · In reply to: #80177

Julien Pauli wrote on 05/01/2015 16:19:
> Hello.
>
> Can't this be already done somehow ? In RINIT stage obviously.
> I don't understand why to change our API to add a feature we already can
> use ?
>
> Julien.P

The RFC explains the motivation reasonably clearly. In particular:

 > Using RINIT is error prone and a little bit dangerous, because is a 
bit too early for some data to be cleanly created (globals).

Basically, it's a standardised implementation, and allows the code to 
run at a more appropriate phase of execution.

-- 
Rowan Collins
[IMSoP]

---

## #80180 — Pierre Joye — 2015-01-05T16:34:39+00:00

URL: https://externals.io/message/80142#80180 · In reply to: #80175

>
>
> 
> > […]
extensions
> > […]
that are
> > […]
up to
> > […]
On any case the file has to be at the right place, etc.
>
> The shared object file has to be at the right place as well.

Make install, build dependent. Include paths are runtime dependent. It
makes a slight bigger difference.

> > […]
config using the existing directive with options like first, before, last
for the insert position.
>
> This assumes that we have dependencies between extensions, which we don't
have anyways. Now if extensions depend on each other the order is
important. I assume that the loading order is also the order that the MINIT
is called, which then would also put dependent php files in order.
>
> > […]
as it can be very useful in user land as well.
>
> Yes maybe, although I don't see the benefit for userland TBH, compared to
extensions. Extensions are about declaring functions/classes, prepend is
normally about actually "executing"/running code.

Not always really. But the two are so similar than I have some hard time to
see why it should be different. Feel free to enlighten me :)

Cheers,
Pierre

---

## #80181 — Julien Pauli — 2015-01-05T16:36:23+00:00

URL: https://externals.io/message/80142#80181 · In reply to: #80178

On Mon, Jan 5, 2015 at 5:26 PM, Rowan Collins <rowan.collins@gmail.com>
wrote:

> Julien Pauli wrote on 05/01/2015 16:19:
>
> > […]
>
> The RFC explains the motivation reasonably clearly. In particular:
>
> > […]
> too early for some data to be cleanly created (globals).
>

This is a problem that can already be dealt with.
Globals are created before RINIT.



> Basically, it's a standardised implementation, and allows the code to run
> at a more appropriate phase of execution.


Yes, I understand the RFC as a standardisation of a concept that is very
uncommonly used, and that could lead to problems against OPcode caches.
Having extensions declaring php files to load, knowing we can `dl()` them at
runtime, we have static vs dynamic extensions... That smells problems to me
(at least its not as easy as the RFC actually states) , however, nothing is
impossible.


Julien.P

---

## #80196 — Sara Golemon — 2015-01-05T18:32:59+00:00

URL: https://externals.io/message/80142#80196 · In reply to: #80142

> I want to open discussion on my RFC to strengthen the ability of extensions
> to provide functionality to developers in both C **and** PHP code.
>
> For this extensions can add PHP files to a list of "prepend files" that are
> part of every request execution exactly the same way the INI
> auto_prepend_file functionality works:
>
> https://wiki.php.net/rfc/extension_prepend_files
>
> I propose implementation details in the RFC, but they are completely up to
> discussion. I am even sure there is probably a better way than what I
> proposed, because I am not familiar with the code.
>
So, I've been meaning to propose something *like* this, but with a few
key implementation detail differences:

1) Create the notion of "Persistent User
Functions/Classes/Constants/etc...".  This is an important perf item
as reloading a prepend file on EVERY request is costly.  Less costly
with an opcache, sure, but still costly.  Making the entries
persistent lets us deal with this once in the process lifetime and
keep the data around.

2) Embedded text sections.  It's possible to place the raw PHP code
into the compiled .so/.dylib/.dll file and fetch it out for
compilation at runtime.  This enables easy bundling of the loaded
scripts, obviates the need to track what directory the files are in,
and generally makes it cleaner. ((Pre-compiling to bytecode is an
option, but it complicates the reloading and doesn't really buy us
much.))

-Sara

---

## #80199 — Stanislav Malyshev — 2015-01-05T20:52:27+00:00

URL: https://externals.io/message/80142#80199 · In reply to: #80196

Hi!

> 1) Create the notion of "Persistent User
> Functions/Classes/Constants/etc...".  This is an important perf item
> as reloading a prepend file on EVERY request is costly.  Less costly
> with an opcache, sure, but still costly.  Making the entries
> persistent lets us deal with this once in the process lifetime and
> keep the data around.

That looks like much bigger can of worms. I.e. would these classes be
immutable? Would we ban functions/methods from having static vars? How
would we achieve that? etc. etc.

> 2) Embedded text sections.  It's possible to place the raw PHP code
> into the compiled .so/.dylib/.dll file and fetch it out for
> compilation at runtime.  This enables easy bundling of the loaded

I guess it is possible, but why - what's wrong with plain old files and
phars?

> scripts, obviates the need to track what directory the files are in,

You still need to address the files somehow if you plan to have more
than one, which would eventually lead you to the need to namespace it
since people tend to name their files "utils.php". Which would be
essentially the same as directories. So I'm not sure I understand the
win here.
-- 
Stas Malyshev
smalyshev@gmail.com

---

## #80218 — francois@tekwire.net — 2015-01-06T04:21:26+00:00

URL: https://externals.io/message/80142#80218 · In reply to: #80196

> -----Message d'origine-----
> De : php@golemon.com [mailto:php@golemon.com] De la part de Sara Golemon
>
> So, I've been meaning to propose something *like* this, but with a few
> key implementation detail differences:
> 
> 1) Create the notion of "Persistent User Functions/Classes/Constants/etc
> 
> 2) Embedded text sections

First, persistent PHP code or data (NOT reloading code for each request) is a huge can of worms. If Sara decides to re-launch the idea, that will be great but the subject is probably out of scope here.

IMHO, what we need here is a generic mechanism to embed PHP code in C extensions and, then, execute it. It should define a way to embed PHP scripts as C strings at compile time, how to make these scripts known and accessible from the PHP core, and how to execute them when needed.

Instead of including the runtime code in every extensions, as it is done in ext-embed, I would prefer an extension which would provide this service to other 'client' extensions. It would define a stream wrapper to access the registered PHP scripts. Script registration would be registered in persistent memory during MINIT. The registration would return an ID for each registered script. These IDs would be stored by the client extension and would be used to derive a stream-wrapped path when the client decides to execute a registered script. These paths would uniquely reference the scripts, which would allow to opcode-cache them.

As a specific case, if an extension wants to execute some PHP code at the beginning of each request, it can execute its script(s) during RINIT, but it is just a use case of a more general mechanism. RINIT execution order can be resolved using module dependencies.

Extending the mechanism to userspace 'plain file' scripts could be provided by a 'bridge'. The user could register a plain file script, whose content would be stored in persistent memory, with a flag that would cause the script to be loaded during every RINIT.

One more word about executing scripts during every RINIT : even with opcode caches, as Sara notes, the performance hit is not negligible. The question is always the same : What is the percentage of requests that will really use the classes/functions we define there ? Remember that the list of scripts is hardcoded in an extension. If the extension wants to allow conditional loading for different features, it needs to define appropriate ini settings. Choosing the list of scripts at compile time is another option but would make the distribution of precompiled binaries complex.

I personally favor another approach. I still use the PHK extension as an example of this 'intermediate' approach. This extension defines C-levels front-end classes. These classes contain the 'fast' code. When this code needs to access 'slow' PHP code, it executes the PHP scripts it needs, then calls the just-defined PHP classes.  This way, we preserve the possibility to code a big part of the extension in PHP, without the overhead of loading the PHP code at the beginning of each request.

Thanks for your attention :)

François

---

## #80221 — Pierre Joye — 2015-01-06T06:48:40+00:00

URL: https://externals.io/message/80142#80221 · In reply to: #80218

hi,


> > […]
>
> First, persistent PHP code or data (NOT reloading code for each request) is a huge can of worms. If Sara decides to re-launch the idea, that will be great but the subject is probably out of scope here.
>
> IMHO, what we need here is a generic mechanism to embed PHP code in C extensions and, then, execute it. It should define a way to embed PHP scripts as C strings at compile time, how to make these scripts known and accessible from the PHP core, and how to execute them when needed.
>
> Instead of including the runtime code in every extensions, as it is done in ext-embed, I would prefer an extension which would provide this service to other 'client' extensions. It would define a stream wrapper to access the registered PHP scripts. Script registration would be registered in persistent memory during MINIT. The registration would return an ID for each registered script. These IDs would be stored by the client extension and would be used to derive a stream-wrapped path when the client decides to execute a registered script. These paths would uniquely reference the scripts, which would allow to opcode-cache them.
>
> As a specific case, if an extension wants to execute some PHP code at the beginning of each request, it can execute its script(s) during RINIT, but it is just a use case of a more general mechanism. RINIT execution order can be resolved using module dependencies.
>
> Extending the mechanism to userspace 'plain file' scripts could be provided by a 'bridge'. The user could register a plain file script, whose content would be stored in persistent memory, with a flag that would cause the script to be loaded during every RINIT.
>
> One more word about executing scripts during every RINIT : even with opcode caches, as Sara notes, the performance hit is not negligible. The question is always the same : What is the percentage of requests that will really use the classes/functions we define there ? Remember that the list of scripts is hardcoded in an extension. If the extension wants to allow conditional loading for different features, it needs to define appropriate ini settings. Choosing the list of scripts at compile time is another option but would make the distribution of precompiled binaries complex.
>
> I personally favor another approach. I still use the PHK extension as an example of this 'intermediate' approach. This extension defines C-levels front-end classes. These classes contain the 'fast' code. When this code needs to access 'slow' PHP code, it executes the PHP scripts it needs, then calls the just-defined PHP classes.  This way, we preserve the possibility to code a big part of the extension in PHP, without the overhead of loading the PHP code at the beginning of each request.
>
> Thanks for your attention :)

It looks to me that it is going slightly too far, or I totally miss
why it is such a critical feature.

As a developer of (too) many extensions, I can only agree with other
developers saying that many times, writing some glue code in PHP is
way easier than doing it in C using the PHP internals APIs. This is a
one of the biggest problem PHP internals have. Sara and many other
pointed out this problem numerous times in the past. PHP 7 is an
unique opportunity to provide easier APIs to develop extensions even
if we keep the existing ones for obvious reasons.

For example HHVM provides a neat one, which is simply PHP for simple
cases. Complex cases allow advanced the native support is also
supported. See https://github.com/facebook/hhvm/wiki/Extension-API.

Zephir (https://github.com/phalcon/zephir) provides also a clean
solution and easier to maintain or implement PHP extensions.

Python or Perl also provides much cleaner APIs and mix of C and
scripts for extensions developers.

To me, it looks like this is what we should try to solve instead of
creating something we will most likely regret very soon. Benjamin's
original proposal (if technically possible in such a simple way, but I
am not sure about that :) ) is somehow more acceptable than Sara's one
(statically built scrpts with the extension. For one, statically build
scripts into extensions looks to me like statically linking libc. It
also kills any of the advantages of having a glue code, from a release
point of view.

The last thing I do not understand, from Benjamin's point of view, is
the performance part. PHP glue code is used for areas where
performance is not a matter, but then we may end adding this
featurebecause the performance impact is too big. What do I miss? If
the prepend or script loading process are too slow, we should try to
fix this bottleneck instead of opening yet another can of worms.
However I do not see this part of a request as the bottlenecks for
most PHP apps (with opcache).

I do not try to be negative or aggressively opposed to this feature. I
simply think we are trying to solve the wrong parts of the problems.

Cheers,
-- 
Pierre

@pierrejoye | http://www.libgd.org

---

## #80222 — Pierre Joye — 2015-01-06T06:53:54+00:00

URL: https://externals.io/message/80142#80222 · In reply to: #80221

> For example HHVM provides a neat one, which is simply PHP for simple
> cases. Complex cases allow advanced the native support is also
> supported. See https://github.com/facebook/hhvm/wiki/Extension-API.

... Complex cases can be implemented using the native support. Sorry
for some c/p mess while rephrasing it :)

---

## #80227 — Derick Rethans — 2015-01-06T11:24:14+00:00

URL: https://externals.io/message/80142#80227 · In reply to: #80199

> > […]
> 
> I guess it is possible, but why - what's wrong with plain old files and
> phars?

Deployment and installation. Right now, "pecl install extension" doesn't 
really allow you to also install **and** load a PHP script on every 
request. Such a PHP script could define extra classes, that are written 
in PHP - because maintainting them as a C implementation would be way 
more work. Having users install another set of PHP files for every 
project is error prone, and frankly, bad for user experience. I can 
definitely see the use case here, and it's probably something we'd want 
to use for the new MongoDB driver.

cheers,
Derick

---

## #80230 — Benjamin Eberlei — 2015-01-06T11:37:50+00:00

URL: https://externals.io/message/80142#80230 · In reply to: #80227

> 
>
> > […]
>
> Deployment and installation. Right now, "pecl install extension" doesn't
> really allow you to also install **and** load a PHP script on every
> request. Such a PHP script could define extra classes, that are written
> in PHP - because maintainting them as a C implementation would be way
> more work. Having users install another set of PHP files for every
> project is error prone, and frankly, bad for user experience. I can
> definitely see the use case here, and it's probably something we'd want
> to use for the new MongoDB driver.
>

Yes the deployment aspect isn't discussed in my RFC and that is an
important part.

Frankly most of the ideas presented here are way better than the hack I
have come up with, the question is how to proceed to refine this idea?

The general plan seems to be to have a way to embed PHP code into the
shared object, for example using Autoconf Macros (like the embed extension
mentioned above does)

>
> cheers,
> Derick

---

## #80231 — Pierre Joye — 2015-01-06T11:39:38+00:00

URL: https://externals.io/message/80142#80231 · In reply to: #80227

> 
>
> > […]
>
> Deployment and installation. Right now, "pecl install extension" doesn't
> really allow you to also install **and** load a PHP script on every
> request. Such a PHP script could define extra classes, that are written
> in PHP - because maintainting them as a C implementation would be way
> more work. Having users install another set of PHP files for every
> project is error prone, and frankly, bad for user experience. I can
> definitely see the use case here, and it's probably something we'd want
> to use for the new MongoDB driver.


The more I read the replies here the more I think we have two issues
two solves. That does not mean this proposal (how it will be done
seems to be very open at this point) is a bad idea.

1. Current internals APIs are not good enough for easy to implement
and maintain exposed classes (declaration, implementation, etc.)
2. We have no easy way to actually release and deploy adhoc scripts,
used by a given extension

For 1., as stated earlier, we really need to work on that. The sooner
the better.

For 2., it is one of the thing I can imagine implementing in pickle.
Or even better add it a s part of the build scripts and macros. Either
will work, even for binary install on windows f.e.. I would really
like to define a clear location relative to the extension directory.
This location will be used by this new feature, if implemented. I also
think that it should be either part of the current prepend setting, by
default and system only, or another setting. What I really consider as
a bad practice is any kind of bundling scripts in the extensions, that
will be a real pain to maintain and it opens some unknown can of
worms. Distros may also prefer to have that script outside the
extension, easier for cherry picks update when necessary (f.e.
security fixes).

Please take it as a brainstorming, thoughts?

---

## #80232 — Pierre Joye — 2015-01-06T11:41:01+00:00

URL: https://externals.io/message/80142#80232 · In reply to: #80230

> The general plan seems to be to have a way to embed PHP code into the
> shared object, for example using Autoconf Macros (like the embed extension
> mentioned above does)

Just for the record, stated it before but... :)

I do think it is a very bad idea to do it. See my other replies for the reasons.

-- 
Pierre

@pierrejoye | http://www.libgd.org

---

## #80234 — francois@tekwire.net — 2015-01-06T14:20:51+00:00

URL: https://externals.io/message/80142#80234 · In reply to: #80231

> De : Pierre Joye [mailto:pierre.php@gmail.com]

> 2. We have no easy way to actually release and deploy adhoc scripts,
> used by a given extension
> 
> For 2., it is one of the thing I can imagine implementing in pickle.
> Or even better add it a s part of the build scripts and macros. Either
> will work, even for binary install on windows f.e.. I would really
> like to define a clear location relative to the extension directory.
> This location will be used by this new feature, if implemented. I also
> think that it should be either part of the current prepend setting, by
> default and system only, or another setting. What I really consider as
> a bad practice is any kind of bundling scripts in the extensions, that
> will be a real pain to maintain and it opens some unknown can of
> worms. Distros may also prefer to have that script outside the
> extension, easier for cherry picks update when necessary (f.e.
> security fixes).

I am sorry to say that but, with all due respect, I have a totally opposite opinion.

IMHO, this PHP code (and any other data we want to embed) is an integral part of the extension. A compiled extension is a consistent piece of code, it is contained in a single file and should not be split to separate files.

The first reason is that, if we consider a released extension as a conceptual unit, the best way to protect its integrity is to store it as a single file. Storing it as separate files brings a lot of potential issues : files can be renamed, deleted, etc. Offline tools like composer can take care of integrity but, from a final user pov, it will never be as clear as a single file (.so for extensions, or package for PHP software).

The second reason, more important, is about inter-communication between C and PHP. I understand the pov : it is easier to allow distros to upgrade an extension's PHP code without upgrading the C code. But, if we consider the PHP code as an integral part of the extension, this should be avoided, as C and PHP code need to be kept in sync.

 If you allow upgrading the PHP code only, you must consider them as two separate pieces of code and, so, consider BC in the way they communicate together. This is a perfectly valid scheme, but, in this case, this PHP code is not part of your extension anymore, it is a separate software with its own version/release numbering, which communicates with your extension. If distros could cherry-pick the C files they want to upgrade, depending on the features they want to provide, would you be ready to keep BC between all your C files ? The same if libc was distributed as a bunch of individually-upgradable files, each defining a function, with consistency ensured by metadata and an offline tool.

So, to summarize my opinion : if an extension writer wants to distribute part of his code in PHP and if he wants this code to be upgradeable in an independent way, he must distribute them as an independent software package, not as part of the extension. The whole code to consider as part of an extension, whatever the language, must be kept in sync. And the best way to achieve this is to store it in a single file.

Regards,

François

---

## #80235 — Pierre Joye — 2015-01-06T14:50:38+00:00

URL: https://externals.io/message/80142#80235 · In reply to: #80234

The whole code to consider as part of an extension, whatever the language,
must be kept in sync. And the best way to achieve this is to store it in a
single file.

I would rather say in a single release and package. Built in scripts in an
extension is an extremely bad step, maintenance, issues management and all
possible complications to allow that may bring. But we get each other view.
I only hope we will not do that.

Also interesting to ignore the other questions, which are imho very
critical. :)

> Regards,
>
> François

---

## #80237 — Benjamin Eberlei — 2015-01-06T14:53:05+00:00

URL: https://externals.io/message/80142#80237 · In reply to: #80235

>
> 
> The whole code to consider as part of an extension, whatever the language,
> must be kept in sync. And the best way to achieve this is to store it in a
> single file.
>
> I would rather say in a single release and package. Built in scripts in an
> extension is an extremely bad step, maintenance, issues management and all
> possible complications to allow that may bring. But we get each other view.
> I only hope we will not do that.
>
> Also interesting to ignore the other questions, which are imho very
> critical. :)
>
How is shipping php code inside so/ddl worse than shipping just the C code
this way? I agree with you it makes changing the PHP code more difficult
(requires recompile), but it makes the deployment and build much simpler.
Including the security concerns.

> > […]

---

Next page: https://externals.io/message/80142.md?page=2
