Learn how php7 achieves maximum performance
PHP7 has been released. As the largest version upgrade and the largest performance upgrade of PHP in 10 years, PHP7 has performed very well in multiple tests. There is an obvious performance improvement, however, in order to maximize its performance, I still want to remind you of a few things.
1. Opcache
Remember to enable Zend Opcache, because PHP7 even without Opcache enabled is faster than PHP-5.6 with Opcache enabled, so this happened during the previous test period Someone has never enabled Opcache. Enabling Opcache is very simple. Add
zend_extension=opcache.so opcache.enable=1 opcache.enable_cli=1
Copy after login
to the php.ini configuration file. 2. Use new The compiler
Use a newer compiler, GCC 4.8 or above is recommended, because only GCC 4.8 or above PHP will enable Global Register for opline and execute_data support, which will bring about a 5% performance improvement (Wordpres Measured from the QPS perspective)
In fact, versions before GCC 4.8 also support it, but we found that there are bugs in its support, so this feature must be enabled in versions 4.8 or above.
3. HugePage
My previous article also introduced: Hugepage to make your PHP7 faster, first enable HugePages in the system, and then enable Opcache's huge_code_pages.
Take my CentOS 6.5 as an example , pass:
$sudo sysctl vm.nr_hugepages=512
Copy after login
Allocate 512 reserved huge page memory:
$ cat /proc/meminfo | grep Huge AnonHugePages: 106496 kB HugePages_Total: 512 HugePages_Free: 504 HugePages_Rsvd: 27 HugePages_Surp: 0 Hugepagesize: 2048 kB
Copy after login
Then add in php.ini:
opcache.huge_code_pages=1
Copy after login
In this way, PHP will use large memory pages to save its own text segments and huge memory allocations to reduce TLB misses and improve performance.
4. Opcache file cache
Enable Opcache File Cache (experimental), by turning this on, we can let Opcache cache the opcode into an external file. For some scripts, there will be a significant performance improvement.
Add in php.ini:
opcache.file_cache=/tmp
Copy after login
In this way, PHP will cache some Opcode binary export files in the /tmp directory, which can exist across the PHP life cycle.
5. PGO
If your PHP is specifically for one project, such as just for your WordPress, or Drupal, or something else, then you can try to use PGO to improve PHP specifically for your This project improves performance.
Specifically, WordPress 4.1 is used as the optimization scenario. First, when compiling PHP:
$ make prof-gen
Copy after login
Then train PHP with your project, for example for WordPress:
- That is to say, let php-cgi run the WordPress homepage 100 times to generate some profile information in the process.
$ sapi/cgi/php-cgi -T 100 /home/huixinchen/local/www/htdocs/wordpress/index.php >/dev/null
Copy after login
Finally:
$ make prof-clean $ make prof-use && make install
Copy after loginAt this time The PHP7 you compile is the highest performance compiled version tailored for your project.
Recommended tutorial: "php video tutorial"
The above is the detailed content of Learn how php7 achieves maximum performance. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

In order to improve the performance of Go applications, we can take the following optimization measures: Caching: Use caching to reduce the number of accesses to the underlying storage and improve performance. Concurrency: Use goroutines and channels to execute lengthy tasks in parallel. Memory Management: Manually manage memory (using the unsafe package) to further optimize performance. To scale out an application we can implement the following techniques: Horizontal Scaling (Horizontal Scaling): Deploying application instances on multiple servers or nodes. Load balancing: Use a load balancer to distribute requests to multiple application instances. Data sharding: Distribute large data sets across multiple databases or storage nodes to improve query performance and scalability.

C++ performance optimization involves a variety of techniques, including: 1. Avoiding dynamic allocation; 2. Using compiler optimization flags; 3. Selecting optimized data structures; 4. Application caching; 5. Parallel programming. The optimization practical case shows how to apply these techniques when finding the longest ascending subsequence in an integer array, improving the algorithm efficiency from O(n^2) to O(nlogn).

By building mathematical models, conducting simulations and optimizing parameters, C++ can significantly improve rocket engine performance: Build a mathematical model of a rocket engine and describe its behavior. Simulate engine performance and calculate key parameters such as thrust and specific impulse. Identify key parameters and search for optimal values using optimization algorithms such as genetic algorithms. Engine performance is recalculated based on optimized parameters to improve its overall efficiency.

The performance of Java frameworks can be improved by implementing caching mechanisms, parallel processing, database optimization, and reducing memory consumption. Caching mechanism: Reduce the number of database or API requests and improve performance. Parallel processing: Utilize multi-core CPUs to execute tasks simultaneously to improve throughput. Database optimization: optimize queries, use indexes, configure connection pools, and improve database performance. Reduce memory consumption: Use lightweight frameworks, avoid leaks, and use analysis tools to reduce memory consumption.

Effective techniques for quickly diagnosing PHP performance issues include using Xdebug to obtain performance data and then analyzing the Cachegrind output. Use Blackfire to view request traces and generate performance reports. Examine database queries to identify inefficient queries. Analyze memory usage, view memory allocations and peak usage.

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Nginx performance tuning can be achieved by adjusting the number of worker processes, connection pool size, enabling Gzip compression and HTTP/2 protocols, and using cache and load balancing. 1. Adjust the number of worker processes and connection pool size: worker_processesauto; events{worker_connections1024;}. 2. Enable Gzip compression and HTTP/2 protocol: http{gzipon;server{listen443sslhttp2;}}. 3. Use cache optimization: http{proxy_cache_path/path/to/cachelevels=1:2k

Performance optimization for Java microservices architecture includes the following techniques: Use JVM tuning tools to identify and adjust performance bottlenecks. Optimize the garbage collector and select and configure a GC strategy that matches your application's needs. Use a caching service such as Memcached or Redis to improve response times and reduce database load. Employ asynchronous programming to improve concurrency and responsiveness. Split microservices, breaking large monolithic applications into smaller services to improve scalability and performance.
