Several optimization schemes to improve the running speed of PHP program

Source: Internet
Author: User

1, the server uses the Linux system

Linux system server in many ways than Windows excellent, many places performance difference is very big, if your server does not have ASP, ASP, and so on, strongly recommend the use of Linux system, Centos, Ubuntu, Debian and other systems are Linux kernel. Not only Linux performance is good, and Linux server is also cheap, especially foreign servers, because Windows Server is charged, many foreign win servers are more expensive than Linux.

Although Linux systems are much more complex to operate than Windows, we can look at the information science, as long as you learn basic server installation and use of operations, you will love Linux. At the end of the day there will be an introductory tutorial, so that everyone can easily use the Linux server.

2. Use Nginx or Apache to run PHP

Many use win server webmaster, are using IIS to run PHP, and even some people use IIS6 to run, which greatly affect the performance of PHP, access to a small number of cases may be less obvious, access to a large can feel the difference. If you insist on using the win server, it is recommended to use Nginx or Apache to run PHP. Do not set the environment, we recommend the use of Phpstudy software to build a button, you can switch Nginx, Apache, IIS and PHP version.

3. Start using PHP7

If your program supports PHP7, it is strongly recommended that you use PHP7,PHP7 relative php5.x with a large performance boost, which will be two or three times times faster than the latter in many algorithms! If your program is not compatible with PHP7, then try to upgrade to PHP5.6. Fire-side search is perfect for PHP7 support.

4. Use Opcache to accelerate PHP operation

Opcache improves PHP performance by storing PHP script precompiled bytecode in shared memory, and the benefit of storing precompiled bytecode is to eliminate the overhead of loading and parsing PHP scripts every time. The Opcache extension has been bundled in PHP 5.5.0 and later.

It's easy to turn on Opcache.

1. Open php.ini File
2. Find: [Opcache], set to:

    1. [Opcache]
    2. ; DLL address
    3. Zend_extension=php_opcache.dll
    4. ; Switch Open
    5. Opcache.enable=1
    6. ; Open CLI
    7. Opcache.enable_cli=1
    8. ; Available memory, as appropriate, in megabytes: Mb
    9. opcache.memory_consumption=528
    10. ; Zend Optimizer + The total memory of the string in the staging pool. (Unit: MB)
    11. Opcache.interned_strings_buffer=8
    12. ; For multiple cache file limits, you can try to increase this value by less than 100% of the hit rate.
    13. opcache.max_accelerated_files=10000
    14. ; Opcache will check the file modification time within a certain time, here set the check time period, the default is 2, positioning for seconds
    15. Opcache.revalidate_freq=1
    16. ; Turn on quick close to open this the memory recovery rate will increase when PHP Request shutdown
    17. Opcache.fast_shutdown=1
5. Avoid frequent database operation

Most web site bottlenecks are the operation of the database this block, many times we do not need to frequently access the database, when we can cache the data, with Redis, memcache or file cache can be. For example, the official web site of the fire terminal, most of the pages of data are cached, are not required to read the database.

6, using SSD hard disk to do the server

SSD is only to improve the file read and write speed, the general implementation of PHP has little impact, but if you need PHP to frequently manipulate files, the SSD hard disk will play its role.

PHP.ini configuration as follows

Zend_extension=/usr/local/php/lib/php/extensions/no-debug-non-zts-20151012/opcache.so
Opcache.enable=1
opcache.memory_consumption=128
Opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
Opcache.revalidate_freq=60
Opcache.fast_shutdown=1
Opcache.enable_cli=1

Several optimization schemes to improve the running speed of PHP program

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.