Zend OPcache
1). Starting from PHP5.0, bytecode caching is built-in, called Zend OPcache. Because PHP is an interpretive language, when the PHP interpreter executes PHP scripts, it will parse the PHP script code, generate a series of Zend opcodes, and then execute bytecode. This is the case with each HTTP request, which will consume a lot of resources. Using bytecode cache can cache precompiled bytecode, reduce response time, and reduce the pressure on system resources.
Enable Zend OPcache
By default, Zend OPcache is not started. If you compile PHP yourself, the command must include the following options when executing:
--enable-opcache
After compiling PHP, you must also specify the extension path of Zend OPcache in the file, as shown below:
zend_extension=/path/to/
After PHP is successfully compiled, the file path of the Zend OPcache extension will be displayed immediately. You can use the following command to find the path to this PHP extension
php-config --extension-dir
Then use the following code to confirm that the extension is running normally
<?php phpinfo();
Configuring Zend OPcache
Recommended configuration
opcache.validate_timestamps = 1 //Set '0' in production environmentopcache.revalidate_freq = 0 opcache.memory_comsumption = 64 opcache.interned_strings_buffer = 16 opcache.max_accelerated_files = 4000 opcache.fast_shutdown = 1
You can visit the official PHP website to view detailed settings.
Using Zend OPcache
1). The production environment can set opcache.validate_timestamps=0. In the development environment, you need to set it to 1
Built-in HTTP server
1). Start php -S localhost:4000 -c app/config/
2). The .htaccess file is not supported. Meaning that controller mode is not supported. The front-end controller is used to forward all HTTP requests, which need to be implemented through .htaccess files or rewrite rules.
3). The above functions can be implemented using router scripts. But only supports a small number of URL rewriting rules. php -S localhost:8000
4). Determine which server is used:
<?php if (php_sapi_name() === 'cli-server') { //Php built-in server} else { // Other web servers}
Special series
PHP special series directory address:/xx19941215/…
The PHP special series is expected to be written about twenty articles, mainly summarizing the basic knowledge that is easy to ignore in our daily PHP development and some practical suggestions on specifications, deployments, and optimization in modern PHP development. At the same time, there is also an in-depth study on the characteristics of the Javascript language.
Summarize
The above is the new PHP feature of bytecode cache and built-in server introduced to you by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support for my website!