rfc:url-opcode-cache
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revisionLast revisionBoth sides next revision | ||
rfc:url-opcode-cache [2017/05/25 17:45] – created francois | rfc:url-opcode-cache [2017/06/23 10:45] – francois | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== PHP RFC: Add support for stream-wrapped URLs in opcode cache ====== | ====== PHP RFC: Add support for stream-wrapped URLs in opcode cache ====== | ||
- | * Version: 1.0 | + | * Version: 1.2 |
- | * Date: 2017-05-25 | + | * Date: 2017-06-05 |
* Author: François Laupretre, francois@tekwire.net | * Author: François Laupretre, francois@tekwire.net | ||
- | * Status: | + | * Status: |
* First Published at: http:// | * First Published at: http:// | ||
Line 11: | Line 11: | ||
It is an extension of the ' | It is an extension of the ' | ||
- | |||
- | ===== Proposal ===== | ||
When stream wrappers were introduced in PHP, their relationship with opcode | When stream wrappers were introduced in PHP, their relationship with opcode | ||
caches was not a problem, as they were mostly used to access remote data. The | caches was not a problem, as they were mostly used to access remote data. The | ||
need for a better interaction arose with package systems, like phar and phk, as | need for a better interaction arose with package systems, like phar and phk, as | ||
- | these stream wrappers | + | these sytems use stream wrappers |
- | the scripts | + | |
- | Historically, | + | Historically, |
- | URL is considered as opcode-cacheable | + | - every URL may be considered as opcode-cacheable, |
- | a list of 'cacheable' protocols is declared explicitely in the code. opcache | + | - In order to avoid this, opcache |
- | declared | + | |
- | I consider that we need a more generic system, which must allow any PHP code handled via a stream wrapper (' | + | So, I consider that we need a more generic system, which must allow any PHP code handled via a stream wrapper (' |
+ | |||
+ | ===== Proposal ===== | ||
My previous RFC proposed the implementation of an ' | My previous RFC proposed the implementation of an ' | ||
- | * An operation named ' | + | * An operation named ' |
* A new C function named php_stream_cache_key(zend_string *path, int options, php_stream_context *context) is defined. It determines the right wrapper from the path it receives and forwards the request to the corresponding stream_cache_key() function, if it exists. If the stream_cache_key() element is not defined, NULL is returned. | * A new C function named php_stream_cache_key(zend_string *path, int options, php_stream_context *context) is defined. It determines the right wrapper from the path it receives and forwards the request to the corresponding stream_cache_key() function, if it exists. If the stream_cache_key() element is not defined, NULL is returned. | ||
- | * Userspace stream wrappers can define a method named cache_key(path [, | + | * Userspace stream wrappers can define a method named cache_key(path [, |
* For completeness, | * For completeness, | ||
- | Using a (zend_string *) for input and output allows the mechanism to be very fast because, in most cases, when an URL is cacheable, the key to use will be the path itself. | + | Using a (zend_string *) for input and output allows the mechanism to be very fast because, in most cases, when an URL is cacheable, the key to use will be the path itself. |
- | In order to ensure key unicity, | + | /** |
+ | * Called by the opcode cache to get the key to use when caching this URL | ||
+ | */ | ||
+ | static zend_string *phar_wrapper_cache_key(php_stream_wrapper *wrapper | ||
+ | , zend_string *url, int options, php_stream_context *context) | ||
+ | { | ||
+ | /* Phar URLs are always cacheable */ | ||
+ | zend_string_addref(url); | ||
+ | return url; | ||
+ | } | ||
+ | /* }}} */ | ||
- | The stream wrapper has the responsibility to ensure that the data associated with a given key will always be the same. | + | In order to ensure key unicity, the returned string must start with the same '< |
+ | |||
+ | The stream wrapper has the responsibility to ensure that the data associated with a given key will always be the same. If this is not the case (e.g. if a ' | ||
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== | ||
Line 49: | Line 59: | ||
===== Proposed PHP Version(s) ===== | ===== Proposed PHP Version(s) ===== | ||
- | Next | + | 7.2 |
===== RFC Impact ===== | ===== RFC Impact ===== | ||
Line 58: | Line 68: | ||
==== To Existing Extensions ==== | ==== To Existing Extensions ==== | ||
- | Phar needs to implement | + | Phar implements |
The same for the plain files wrapper. | The same for the plain files wrapper. | ||
- | Both changes are included in the PR below. | + | No other core extension needs to be modified. |
+ | |||
+ | When 3rd-party extensions decide to have the benefit of the new feature, they will just implement an additional ' | ||
+ | |||
+ | Userspace stream wrappers may just define a new ' | ||
==== To Opcache ==== | ==== To Opcache ==== | ||
Line 68: | Line 82: | ||
Opcode cache must implement the following logic : | Opcode cache must implement the following logic : | ||
- | * If the received path is a ' | + | |
- | * If the returned value is null, path is non cacheable. | + | * If the returned value is null, path is non cacheable. |
- | * If the returned value is non null, use this value as key to search or register the data. | + | * If the returned value is non null, use this value as key to search or register the data. |
- | These changes are NOT included in the PR below because opcache code is a performance-critical part of the core. As the change is not trivial and requires some re-organizations in the way functions call themselves, I would prefer someone more familiar with this code to implement these changes. | + | These changes are NOT included |
==== New Constants ==== | ==== New Constants ==== | ||
Line 79: | Line 93: | ||
===== Open Issues ===== | ===== Open Issues ===== | ||
- | |||
- | * Security check on the key returned by userspace wrappers is not implemented yet. I'll add it ASAP. | ||
===== Unaffected PHP Functionality ===== | ===== Unaffected PHP Functionality ===== | ||
Line 102: | Line 114: | ||
===== References ===== | ===== References ===== | ||
- | |||
- | Pull request: [[https:// | ||
===== Rejected Features ===== | ===== Rejected Features ===== | ||
rfc/url-opcode-cache.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1