CodeIgniter4
CodeIgniter4 copied to clipboard
feat: additional `opcache` setting in check php.ini
Description I think this additional needed to recommendation.
Checklist:
- [x] Securely signed commits
- [ ] Component(s) with PHPDoc blocks, only if necessary or adds value
- [x] Unit testing, with >80% coverage
- [ ] User guide updated
- [x] Conforms to style guide
I have concerns.
- Too many items in the output can be difficult to read. I want to display only the really important items.
- The current output is too wide to see.
- It is difficult to determine recommended values for OPCache settings because they are highly dependent on the environment.
+---------------------------------+---------+---------+-------------+------------------------------------------------------------------------------------------------------------------------------------------+
| Directive | Global | Current | Recommended | Remark |
+---------------------------------+---------+---------+-------------+------------------------------------------------------------------------------------------------------------------------------------------+
| error_reporting | 32767 | 32767 | 5111 | |
| display_errors | 1 | 1 | 0 | |
| display_startup_errors | 1 | 1 | 0 | |
| log_errors | 1 | 1 | | |
| error_log | | | | |
| default_charset | UTF-8 | UTF-8 | UTF-8 | |
| memory_limit | 1G | 1G | | > post_max_size |
| post_max_size | 8M | 8M | | > upload_max_filesize |
| upload_max_filesize | 2M | 2M | | < post_max_size |
| request_order | GP | GP | GP | |
| variables_order | GPCS | GPCS | GPCS | |
| date.timezone | UTC | UTC | UTC | |
| mbstring.language | neutral | neutral | neutral | |
| opcache.enable | 1 | 1 | 1 | |
| opcache.enable_cli | 0 | 0 | | |
| opcache.jit | tracing | tracing | | |
| opcache.jit_buffer_size | 0 | 0 | | |
| opcache.memory_consumption | 128 | 128 | 728 | Increasing the configured memory size (MB) will improve performance by caching those files (consideration based on free space of memory) |
| opcache.interned_strings_buffer | 8 | 8 | 64 | |
| opcache.max_accelerated_files | 10000 | 10000 | 56000 | Increasing the configured accelerated will many cache files into OPCache hash table |
| opcache.max_wasted_percentage | 5 | 5 | 15 | |
| opcache.validate_timestamps | 1 | 1 | 0 | |
| opcache.revalidate_freq | 2 | 2 | 0 | |
| opcache.save_comments | 1 | 1 | 1 | |
+---------------------------------+---------+---------+-------------+------------------------------------------------------------------------------------------------------------------------------------------+
Probably a simple mention of opcache On/Off is enough.
Many people don't use the console when developing. Especially the newbies.
I think special attention to php.ini is not required. More questions about apache/nginx
This command is mainly used to check the PHP settings of production environments.
The Recommended column shows the recommended values for production environment. They may differ in development environments. https://codeigniter4.github.io/CodeIgniter4/installation/running.html#checking-php-ini-settings
@ddevsr If you want to show opcache detailed settings, how about adding an argument?
E.g. php spark phpini:check opcache shows only opcache settings.
:wave: Hi, @ddevsr!
We detected conflicts in your PR against the base branch :speak_no_evil:
You may want to sync :arrows_counterclockwise: your branch with upstream!
Ref: Syncing Your Branch
@kenjis @michalsn
$ php spark phpini:check
CodeIgniter v4.5.4 Command Line Tool - Server Time: 2024-08-22 09:50:55 UTC+00:00
+-------------------------+---------------------------------------+---------------------------------------+-------------+---------------------------------------+
| Directive | Global | Current | Recommended | Remark |
+-------------------------+---------------------------------------+---------------------------------------+-------------+---------------------------------------+
| error_reporting | 32767 | 32767 | 5111 | |
| display_errors | 1 | 1 | 0 | |
| display_startup_errors | 1 | 1 | 0 | |
| log_errors | 1 | 1 | | |
| error_log | D:/Project/laragon/tmp/php_errors.log | D:/Project/laragon/tmp/php_errors.log | | |
| default_charset | UTF-8 | UTF-8 | UTF-8 | |
| max_execution_time | 0 | 0 | | The default is 30. |
| memory_limit | 1024M | 1024M | | > post_max_size |
| post_max_size | 2G | 2G | | > upload_max_filesize |
| upload_max_filesize | 2G | 2G | | < post_max_size |
| max_input_vars | 1000 | 1000 | | The default is 1000. |
| request_order | GP | GP | GP | |
| variables_order | GPCS | GPCS | GPCS | |
| date.timezone | Asia/Jakarta | Asia/Jakarta | UTC | |
| mbstring.language | neutral | neutral | neutral | |
| opcache.enable | 0 | 0 | 1 | |
| opcache.enable_cli | 1 | 1 | 1 | |
| opcache.jit | tracing | tracing | tracing | |
| opcache.jit_buffer_size | 128M | 128M | 256 | Adjust with your free space of memory |
| zend.assertions | 1 | 1 | -1 | |
+-------------------------+---------------------------------------+---------------------------------------+-------------+---------------------------------------+
$ php spark phpini:check opcache
CodeIgniter v4.5.4 Command Line Tool - Server Time: 2024-08-22 09:52:13 UTC+00:00
+---------------------------------+---------+---------+-------------+----------------------------------------------------------------------------------+
| Directive | Global | Current | Recommended | Remark |
+---------------------------------+---------+---------+-------------+----------------------------------------------------------------------------------+
| opcache.enable | 0 | 0 | 1 | |
| opcache.enable_cli | 1 | 1 | 1 | |
| opcache.jit | tracing | tracing | tracing | |
| opcache.jit_buffer_size | 128M | 128M | 256 | Adjust with your free space of memory |
| opcache.memory_consumption | 728 | 728 | 512 | Adjust with your free space of memory |
| opcache.interned_strings_buffer | 64 | 64 | 64 | |
| opcache.max_accelerated_files | 58000 | 58000 | 40000 | Find many files in your project (example: find your_project/ -iname *.php|wc -l) |
| opcache.max_wasted_percentage | 15 | 15 | 15 | |
| opcache.validate_timestamps | 0 | 0 | 0 | |
| opcache.revalidate_freq | 0 | 0 | 0 | |
| opcache.save_comments | 0 | 0 | 0 | |
+---------------------------------+---------+---------+-------------+----------------------------------------------------------------------------------+
This looks good, however, I wonder if we should keep all 4 opcache keys in the default table. IMO only the first 2 will be relevant now.
Recommendations by ChatGPT CodeIgniter 4 Assistant
When deploying CodeIgniter 4 (CI4) in a production environment, configuring PHP’s OPcache properly is essential to ensure optimal performance. Below are the recommended values for the specified OPcache settings that should be good for most CI4 users. However, certain values might need adjustment based on the specific needs of your application and server resources.
Recommended PHP ini settings for OPcache in a Production Environment
-
opcache.enable:1(orOn)- Recommendation: Always enable OPcache in production to improve PHP performance by caching compiled script bytecode.
-
opcache.enable_cli:0(orOff)- Recommendation: Generally, you don't need OPcache for CLI scripts. However, if your application runs CLI scripts frequently, you might consider enabling it (
1orOn).
- Recommendation: Generally, you don't need OPcache for CLI scripts. However, if your application runs CLI scripts frequently, you might consider enabling it (
-
opcache.jit:off- Recommendation: Just-In-Time (JIT) compilation can provide performance improvements for certain workloads, but it's generally safe to keep it off unless you've profiled your application and observed tangible benefits from JIT.
-
opcache.jit_buffer_size:0- Recommendation: Set to
0to disable JIT unless you've determined that enabling JIT is beneficial. If enabling JIT, you might set this value between32Mto128Mdepending on available memory and workload characteristics.
- Recommendation: Set to
-
opcache.memory_consumption:128Mto256M- Recommendation: This defines how much memory OPcache can use. For most applications,
128Mshould be sufficient, but for larger applications with many scripts,256Mmight be better.
- Recommendation: This defines how much memory OPcache can use. For most applications,
-
opcache.interned_strings_buffer:8Mto16M- Recommendation: This is used for storing interned strings.
8Mis a good starting point, and16Mcan be used for larger applications.
- Recommendation: This is used for storing interned strings.
-
opcache.max_accelerated_files:10000to20000- Recommendation: This defines the maximum number of files that OPcache can cache. A setting of
10000should work for most applications, but for large codebases,20000might be necessary.
- Recommendation: This defines the maximum number of files that OPcache can cache. A setting of
-
opcache.max_wasted_percentage:5%- Recommendation: When the percentage of wasted memory (due to cache fragmentation) exceeds this value, OPcache will restart. A
5%threshold is generally recommended.
- Recommendation: When the percentage of wasted memory (due to cache fragmentation) exceeds this value, OPcache will restart. A
-
opcache.validate_timestamps:0(orOff)- Recommendation: Disable in production. This improves performance by not checking the script modification time on every request. If your deployment process doesn’t guarantee that updated files are reloaded (e.g., through a cache invalidation strategy), you might need to set this to
1and useopcache.revalidate_freq.
- Recommendation: Disable in production. This improves performance by not checking the script modification time on every request. If your deployment process doesn’t guarantee that updated files are reloaded (e.g., through a cache invalidation strategy), you might need to set this to
-
opcache.revalidate_freq:0to60- Recommendation: If
opcache.validate_timestampsis1, this setting controls how often (in seconds) OPcache will check for script changes. Setting this to0means it checks on every request, which is not recommended for production. Instead, use a value like60to reduce the performance hit.
- Recommendation: If
-
opcache.save_comments:1(orOn)- Recommendation: Keep comments enabled as they are often required by various frameworks and tools. Disabling this can cause issues, especially with Doctrine annotations and other comment-based parsing tools.
Additional Considerations:
- Memory Resources: Ensure your server has enough memory to accommodate these settings. Adjust values like
opcache.memory_consumptionandopcache.jit_buffer_sizebased on your server’s available RAM. - Application Size: Larger applications might require higher values for settings like
opcache.max_accelerated_filesandopcache.memory_consumption. - Testing: Always profile your application with these settings to ensure they are optimal for your specific environment. What works well for one CI4 application might need tweaks for another.
Recommendations by Claude 3.5 Sonnet
As a PHP expert, I can provide recommended values for the PHP ini settings you've listed, specifically tailored for a CodeIgniter 4 production environment. These recommendations should be suitable for most CI4 users, but keep in mind that optimal values can vary depending on your specific application and server resources.
opcache.enable = 1
opcache.enable_cli = 0
opcache.jit = 1255
opcache.jit_buffer_size = 100M
opcache.memory_consumption = 256
opcache.interned_strings_buffer = 16
opcache.max_accelerated_files = 10000
opcache.max_wasted_percentage = 10
opcache.validate_timestamps = 0
opcache.revalidate_freq = 0
opcache.save_comments = 1
Let me explain each setting:
-
opcache.enable = 1: This enables OPcache for web requests, which is crucial for performance in production. -
opcache.enable_cli = 0: OPcache is typically not needed for CLI operations, so it's usually disabled. -
opcache.jit = 1255: This enables JIT compilation with a balanced setting. The value 1255 represents tracing JIT for all JIT-able functions. -
opcache.jit_buffer_size = 100M: This allocates 100MB for JIT-compiled code. Adjust based on available memory, but 100MB is a good starting point. -
opcache.memory_consumption = 256: Allocates 256MB for OPcache. Adjust based on your application size and available memory. -
opcache.interned_strings_buffer = 16: Allocates 16MB for interned strings. This is usually sufficient for most applications. -
opcache.max_accelerated_files = 10000: Allows caching of up to 10,000 files. Adjust based on the number of PHP files in your application. -
opcache.max_wasted_percentage = 10: Restarts the OPcache when 10% of memory is wasted. This helps manage memory efficiently. -
opcache.validate_timestamps = 0: Disables file timestamp checking. This improves performance but requires a server restart or OPcache reset when files are updated. -
opcache.revalidate_freq = 0: Related tovalidate_timestamps. When set to 0 andvalidate_timestampsis off, it never checks file timestamps. -
opcache.save_comments = 1: Preserves comments in the cached files. This is important for CodeIgniter 4, as it uses doc comments for annotations.
These values provide a good starting point for a CodeIgniter 4 production environment. However, you may need to adjust them based on your specific application requirements, server resources, and performance needs. Regular monitoring and tuning can help you find the optimal settings for your particular use case.
I guess there is no consensus on recommended values?