PHP7.0 installation and usage and performance monitoring!

Source: Internet
Author: User
PHP7.0 installation and usage and performance monitoring! PHP 7.0 is released. There are many new versions on the internet. between 7.0 and, several Beta and 8 RC versions have been released before the official release, so there should be no major problems. Today, I upgraded a machine to PHP 7.0 and recorded the following information.

I used Ubuntu 12.04 LTS and found the official version of ppa 7.0 on the internet. Therefore, you do not need to compile it. you can directly install it using the following command.

Install PHP7.0 and extension

Sudo add-apt-repository ppa: ondrej/php-7.0 sudo apt-get update sudo apt-get install php7.0-fpm php7.0-cli php7.0-common php7.0-json php7.0-mysql php7.0-opcache php7.0-curl due to Memcached, Redis extension and the latest version of PHP7 is not supported in pecl, therefore, you need to go to Github to find the PHP7 branch for manual compilation and installation.

The github address for redis and memcached is as follows:

Https://github.com/phpredis/phpredis/ https://github.com/rlerdorf/php-memcached

Redis installation method

Git clone https://github.com/phpredis/phpredis/ cd phpredis
Git checkout php7
Phpize
./Configure make
Ssudo make install

How to install Memcached

Memcached requires the libmemecached library to be downloaded before compilation.

Wget https://launchpad.net/libmemcached/1.0/1.0.18/+download/libmemcached-1.0.18.tar.gz tar-zxvf libmemcached-1.0.18.tar.gz
Cd libmemcached-1.0.18
./Configure make
Sudo make install
Sudo apt-get install pkg-config
Git clone https://github.com/rlerdorf/php-memcached.git
Cd php-memcached
Git checkout php7
Phpize
./Configure make
Sudo make install

The two extensions compiled by yourself need to be manually loaded in the configuration file

Sudo touch/etc/php/mod-available/redis. ini sudo touch/etc/php/mod-available/memcached. ini

Write the content of the two files

Extension = redis. so extension = memcached. so cd/etc/php/7.0/fpm/conf. d sudo ln-s/etc/php/mod-available/redis. ini. /sudo ln-s/etc/php/mod-available/memcached. ini./

If the extension needs to be enabled in the command line, you also need to link it to the cli/conf. d Directory. Restart the server

Sudo service php7.0-fpm restart

Configuration file adjustment because the biggest improvement of PHP7.0 is the performance, it is necessary to enable opcache to ensure that it can play the biggest role. Enable the following configuration of php. ini.

Opcache. enable = 1 opcache. enable_cli = 1
Opcache. file_cache =/tmp
Opcache. error_log =/var/log/opcache_errors.log

The error display is off by default for the package installed by ppa. In addition, the error log is annotated, meaning that no information is displayed when a problem occurs.

Therefore, write the following configuration

Error_log =/var/log/php_errors.log sudo chown www-data.www-data/var/log/php_errors.log

I have installed an Nginx server. make sure that the user group is the same as that of my webserver. otherwise, no prompt will appear. The same is true for the opcache_errors.log file.

For more information about opcache, visit here to view http://www.laruence.com/2015/12/04/3086.html

Exception handling and resolution

After the configuration is complete, you need to run the program. After the old system is transferred to EN PHP7.0, the first error is

09-Dec-2015 12:27:48 Asia/Chongqing] PHP Fatal error: Uncaught Error: Call to undefined function set_magic_quotes_runtime () in/init. php: 46

The set magic quotes_runtime function no longer exists. To be compatible, add a judgment.

If (PHP_VERSION_ID & amp; lt; 70000) {set_magic_quotes_runtime ();}

Monitoring and tuning

I installed the Agent provided by OneAPM in the system. In this way, the operation of the entire system can be monitored in real time. Other versions of the Agent official website have provided download. By the end of this article, PHP 7.0 officially provides a: https://oneapm.kf5.com/attachments/download/366552/0015667f0036f47c827fcb8fcbfbc79/

Before that, more people will use xhprof to detect and optimize the system. However, xhprof cannot properly summarize the samples collected for the overall program performance, nor does it have a good visual curve or Web transaction tracking, this makes it difficult to evaluate system bottlenecks in a short period of time.

So I used OneAPM's PHP Agent to do this. OneAPM also used timed sampling and timed reporting to collect performance information, and officially announced that the resource consumption was less than 5%. However, if PHP7.0 is deployed with a performance improvement of several times, the loss is negligible, and I only deploy one of them on several machines in the cluster.

The following describes basic performance analysis and troubleshooting methods.

For example, you can view the stability of the entire system in a specific period of time on the dashboard. we can see an abnormal peak on the figure, at about 6 o'clock in the morning, remove WEB External by using list filter to see the figure.

Other services are normal. It takes about 10 ms to run to the final PHP layer on average. Go back to the dashboard to view the details.

When you open the details, we can see that the original interface was extracted at six o'clock. The page also monitors the responses of third-party service calls. For example, the 217 ms api. hitokoto. us service.

Let's take a look at the slow SQL monitoring.

The proportion of the response time of a Web transaction shows that the execution time of a script is too long. you can see that the database query accounts for 579 ms.

By switching to the details page, you can see the entire script call process, and finally find that the query executed by the program mysqli. php: 88 takes a long time.

The above is just a basic method to continuously check program stability through OneAPM.

In the daily operation of a program, due to the different access traffic, it is very likely that there will be a large latency at a certain point in time, such as a sudden increase in concurrency or a sudden high proportion of access to a part of the interface, in general, the Apdex indicator looks very beautiful. in this case, OneAPM is easy to find the part that affects the performance of the program, so as to continue to improve or optimize the code.

(The author of this article is a OneAPM user who authorizes OneAPM official blog to forward) OneAPM for PHP can go deep into all PHP applications to complete application performance management and monitoring, including visibility of code-level performance problems, fast identification and tracing of performance bottlenecks, Real User Experience Monitoring, server monitoring, and end-to-end application performance management. For more technical articles, visit the OneAPM official technical blog.

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.