PHP performance Optimization: Configuration Opcache

Source: Internet
Author: User
Enable Opcache in PHP.ini

[opcache]zend_extension =/usr/local/php5/lib/php/extensions/no-debug-zts-20121212/opcache.so; Determines if Zend Opcache is enabledopcache.enable=1; Determines if Zend Opcache is enabled for the CLI version of Php;opcache.enable_cli=0; The Opcache shared memory storage Size.;o pcache.memory_consumption=64; The amount of memory for interned strings in mbytes.opcache.interned_strings_buffer=16; The maximum number of keys (scripts) in the Opcache hash table.; Only numbers between and 100000 is allowed.opcache.max_accelerated_files=3907; The maximum percentage of "wasted" memory until a restart is Scheduled.;o pcache.max_wasted_percentage=5; When this directive was enabled, the Opcache appends the current working; Directory to the script key, thus eliminating possible collisions between; Files with the same name (basename). disabling the directive improves; Performance, but could break existing Applications.;o pcache.use_cwd=1; When disabled, you must reset the Opcache manually or restartthe; Webserver for changes to the filesystem to take effect.opcache.validate_timestamps=0; How often (in seconds) to check file timestamps for changes to the shared; Memory storage allocation. ("1" means validate once per second, but only; once per request. "0" means always validate); opcache.revalidate_freq=2; Enables or disables file search in Include_path optimization;opcache.revalidate_path=0; If disabled, all PHPDOC comments is dropped from the code to reduce the; Size of the optimized code.opcache.save_comments=0; If Disabled, PHPDoc comments is not loaded from SHM, so "Doc comments"; May is always stored (Save_comments=1) and not loaded by applications; That don ' t need them anyway.;o Pcache.load_comments=1; If enabled, a fast shutdown sequence is used for the accelerated codeopcache.fast_shutdown=1; Allow file existence override (File_exists, etc) performance feature.opcache.enable_file_override=1; A bitmask, where each bit enables or disables the appropriate opcache; Passes;opcache.optimization_level=0xffffffff;opcache.inherited_hack=1;opcache.dups_fix=0; The location of the Opcache blacklist file (wildcards allowed).; Each Opcache blacklist file was a text file that holds the names of files; That's should not being accelerated. The file format is to add each filename; to a new line. The filename May is a full path or just a file prefix; (i.e.,/var/www/x blacklists all the files and directories in/var/www; it start with ' X '). Line starting with A; is ignored (comments).; O Pcache.blacklist_filename=/home/ftpcrm/html/crm/blacklist; Allows exclusion of large files from being cached. By default all files; Is Cached.;o pcache.max_file_size=0; Check the cache checksum each N requests.; The default value of "0" means that the checks is Disabled.;o pcache.consistency_checks=0; How long-to-wait (in seconds) for a scheduled restart to begin if the cache; is not being Accessed.;o pcache.force_restart_timeout=180; Opcache error_log file name. Empty string Assumes "stdeRR ".; o pcache.error_log=; All Opcache errors go to the WEB server log.; By default, only fatal errors (level 0) or errors (level 1) is logged.; You can also enable warnings (Level 2), info messages (level 3) or; Debug messages (Level 4).; O pcache.log_verbosity_level=1; Preferred Shared Memory back-end. Leave empty and let the system Decide.;o pcache.preferred_memory_model=; Protect the shared memory from unexpected writing during script execution.; Useful for internal debugging Only.;o Pcache.protect_memory=0

Short explanation

  • Opcache.save_comments
  • In case your application (or the framework it was built on) only uses annotations at development time, can achieve even Better performance by adding opcache.save_comments=0 in your PHP configuration file as well.
  • Opcache.validate_timestamps
  • Opcache.max_accelerated_files
  • Opcache.max_accelerated_files-controls How many PHP files, at the most, can is held in memory at once. It's important that your project have less FILES than whatever you set the this at. My codebase have ~6000 files, so I use the prime number 7963 for Maxacceleratedfiles. You can run "find. -type F-print | grep php | Wc-l "To quickly calculate the number of files in your codebase.
  • Opcache.interned_strings_buffer
  • Opcache.interned_strings_buffer-a pretty neat setting with like 0 documentation. PHP uses a technique called string interning to improve performance? So, for example, if you had the string "Foobar" in your code, internally PHP would store 1 immutable variable F The or this string and just use a pointer to it for the other 999 times your use it. Cool. This setting takes it to the next level? Instead of having a pool of these immutable strings for each single php-fpm process, this setting shares it across all of y Our PHP-FPM processes. It saves memory and improves performance, especially in big applications. The value is set in megabytes and so set it to "16MB". The default is low, 4MB.
  • Opcache.fast_shutdown
  • Opcache.fast_shutdown-another interesting setting with no useful documentation. "allows for faster shutdown". Oh okay. Like that helps me. What this actually does was provide a faster mechanism for calling the deconstructors in your code at the end of a single R Equest to speed up the response and recycle PHP workers so they ' re ready for the next incoming request faster. Set it to 1 and turn it on.

    Viewer Opcache Gui

    References

      1. Speed up your PHP application with Zend Opcache
      2. Best Zend Opcache Settings/tuning/config
      3. Opcode Cache
      4. Understanding Opcache
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.