-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Add wp_ini_parse_quantity() to report numeric php.ini directive values
#2660
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
base: trunk
Are you sure you want to change the base?
Conversation
|
Hi @dmsnell! 👋 Thank you for your contribution to WordPress! 💖 It looks like this is your first pull request to No one monitors this repository for new pull requests. Pull requests must be attached to a Trac ticket to be considered for inclusion in WordPress Core. To attach a pull request to a Trac ticket, please include the ticket's full URL in your pull request description. Pull requests are never merged on GitHub. The WordPress codebase continues to be managed through the SVN repository that this GitHub repository mirrors. Please feel free to open pull requests to work on any contribution you are making. More information about how GitHub pull requests can be used to contribute to WordPress can be found in this blog post. Please include automated tests. Including tests in your pull request is one way to help your patch be considered faster. To learn about WordPress' test suites, visit the Automated Testing page in the handbook. If you have not had a chance, please review the Contribute with Code page in the WordPress Core Handbook. The Developer Hub also documents the various coding standards that are followed:
Thank you, |
|
I suppose that the compatibility check won't block this PR, but I heeded it's advice an in this PHP-compat module fill in the |
bdabf4e to
f130e89
Compare
wp_ini_bytes() to report numeric php.ini directive valueswp_ini_parse_quantity() to report numeric php.ini directive values
c40fb55 to
ee30c16
Compare
Partner to #55635 (https://core.trac.wordpress.org/ticket/55635) Resolves #17725 (https://core.trac.wordpress.org/ticket/17725) When wp_convert_hr_to_bytes() was introduced in [4388] it provided a simplified mechanism to parse the values returned by functions like ini_get() which represent byte sizes. The over-simplified approach has led to issues in that function reporting the wrong byte sizes for various php.ini directives, leading to confusing problems such as uploading files that are rejected improperly or accepted improperly. In this patch we're porting the parser from PHP's own source (which has remained stable for decades and probably can't change without major breakage) in order to more accurately reflect the values it uses when it reads those configurations. This is available in the new function `wp_ini_bytes()` found inside of `wp-includes/php-compat.php` and loaded automatically in `load.php`. Unfortunately PHP doesn't offer a mechanism to read its own internal value for these fields and a 100% port is extremely cumbersome (at best) due to the different ways that PHP and C handle signed integer overflow. These differences should only appear when supplying discouraged/invalid values to the system anyway, and PHP warns that in these situations things are likely to break anyway.
Co-authored-by: Ayesh Karunaratne <Ayesh@users.noreply.github.com>
….ini quantity values
e68d23a to
6265587
Compare
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
This PR for discussion of code and tests - see companion ticket
Trac ticket: https://core.trac.wordpress.org/ticket/55635
Resolves #17725 (https://core.trac.wordpress.org/ticket/17725)
When wp_convert_hr_to_bytes() was introduced in [4388] it provided a simplified
mechanism to parse the values returned by functions like ini_get() which
represent byte sizes. The over-simplified approach has led to issues in that
function reporting the wrong byte sizes for various php.ini directives, leading
to confusing problems such as uploading files that are rejected improperly or
accepted improperly.
In this patch we're porting the parser from PHP's own source (which has
remained stable for decades and probably can't change without major breakage)
in order to more accurately reflect the values it uses when it reads those
configurations. This is available in the new function
wp_ini_parse_quantity()foundinside of
wp-includes/php-compat.phpand loaded automatically inload.php.Unfortunately PHP doesn't offer a mechanism to read its own internal value for
these fields and a 100% port is extremely cumbersome (at best) due to the
different ways that PHP and C handle signed integer overflow. These differences
should only appear when supplying discouraged/invalid values to the system
anyway, and PHP warns that in these situations things are likely to break
anyway.
Sentinel overlap
There is semantic overlap between two values:
These behave differently under comparison, because imposing no limit on memory
use implies that any other actual limit takes precedence over it. Some limit
is more restrictive than no limit.
But then when examining unlimited use, this restriction is more liberal than
any other memory limit than itself. It will always return as not-less-than any
other limit.
There lacks a clear way to disambiguate these.
Testing
Since initially proposing this, PHP updated its own internal parser and now issues warnings for invalid values. It also sets a default value in cases where the value fails to parse.
memory_limit-10PHP Warning: Failed to set memory limit to 0 bytes (Current memory usage is 2097152 bytes) in Unknown on line 01PHP Warning: Failed to set memory limit to 1 bytes (Current memory usage is 2097152 bytes) in Unknown on line 01GshipPHP Warning: Invalid "memory_limit" setting. Invalid quantity "ship": no valid leading digits, interpreting as "0" for backwards compatibility in Unknown on line 01e5PHP Warning: Invalid "memory_limit" setting. Invalid quantity "1e5": unknown multiplier "5", interpreting as "1" for backwards compatibility in Unknown on line 09223372036854775807gPHP Warning: Invalid "memory_limit" setting. Invalid quantity "9223372036854775807g": value is out of range, using overflow result for backwards compatibility in Unknown on line 0