Faster and faster, making php 7 run faster-php Tutorial

Source: Internet
Author: User
Faster and faster, making PHP 7 run faster
Guide PHP 7 is much faster than 5.x. even if only the version upgrade is simple, we still hope it will become faster and faster, and then we will have more fu if we make some minor adjustments, let's try it!

Prerequisites

Speaking of PHP 7, you cannot run LAMP or LEMP. please First prepare the installation of the underlying service.

  • [CentOS 7] integrating Apache, MySQL, and PHP 7 to form a LAMP Server
  • [CentOS 7] integrating Nginx, MariaDB, and PHP 7 to form a LEMP Server
  • In the past, we wanted PHP to accelerate the processing speed. it was usually used with one of APC, eAccelerator, and XCache. if you forget them, you can use OPcache for implementation from now on, it is a PHP support module developed by Huixin, one of the PHP 7 developers. This implementation focuses on the LEMP architecture. the KIT Library uses the Remi version. do not forget to modify the path and set the value according to your actual environment.

    Start setting

    Install the OPcache package.

    sudo yum -y install php70-php-opcache

    Edit the main configuration file.

    sudo vi /etc/opt/remi/php70/php.ini

    Add these parameters.

    zend_extension=opcache.so opcache.enable=1 opcache.enable_cli=1opcache.file_cache=/ home/opcache opcache.huge_code_pages=1

    Start Huge Pages, which is a large temporary paging mechanism. for details, refer to The Linux Kernel Archives-Huge Pages. it is enough to change The test result on my machine to 512.

    sudo sysctl -w vm.nr_hugepages=512

    Create a dedicated OPcache directory.

    sudo mkdir /home/opcache sudo chown nginx:nginx /home/opcache

    Restart the PHP-FPM and you will see that OPcache has started.

    sudo systemctl restart php70-php-fpm

    In addition, we can also install memcached, which, as its name implies, uses memory as the cache to accelerate system operation.

    sudo yum -y install memcached

    Edit the main program file.

    sudo vi /etc/sysconfig/memcached

    There are not many parameters. please modify them as needed.

    PORT-PORT. do not forget to enable the firewall. MAXCONN-total number of connections. CACHESIZE-memory usage, in KB. PORT = "11211" USER = "memcached" MAXCONN = "1024" CACHESIZE = "1024" OPTIONS = ""

    Start memcached and enable it to automatically start after it is started.

    sudo systemctl restart memcached sudo systemctl enable memcached

    Open fire protection wall

    sudo firewall-cmd --permanent --zone=public --add-port=11211/tcp

    Then install the memcached for PHP support module.

    sudo yum -y install php70-php-pecl-memcached

    Restart PHP-FPM.

    sudo systemctl restart php70-php-fpm

    Finally, let's take a look at the phpinfo (); function display result. The memcached section indicates that the operation is successful.

    Test result

    Here, we directly reference the information from netizens on the other side. in this article, OneAPM-uses PHP 7 to accelerate Web applications, he tested 12 types of Wordpress 4.1.1, Drupal 8, phpBB 3.1.3, MediaWiki 1.24.1, Opencart 2.0.2.0, ike1.2.0, Geeklog 2.1.0, Magento 1.9.1.1, Traq 3.5.2, Cachet, Moodle 2.9-dev, and ZenCart 1.5.4 the comparison result of the suite. Taking Wordpress 4.1.1 as an example, we can see that PHP 7 is different from 5.3 ~ The Read speed (Read) and Latency (Latency) of 5.6 are greatly improved.

    References
  • Snow Storm-making PHP7 faster Hugepage
  • Snow and snow-the best Tips for PHP7
  • OneAPM-use PHP 7 to accelerate Web applications
  • Liquidweb-How to Install Memcached on CentOS 7
  • 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.