PHP Performance Optimization--laravel performance optimization

Source: Internet
Author: User
Keywords optimize laravel performance laravel performance tuning
Tags fpm

1. Laravel Official offers some optimizations (Laravel 5.* version):

(1), turn off DEBUG, modify. Env's App_debug=false

(2), sudo php artisan route:cache route cache (cleanup route cache sudo php artisan route: Clear)

(3), sudo php artisan config:cache configuration Cache (cleanup configuration cache sudo php artisan config: clear)

(4), sudo php artisan optimize laravel optimization command, class map load optimization (cleanup cache sudo php artisan clear-compiled)

(5), sudo sudo composer dump-autoload--optimize composer optimization


NOTE * * *: To Laravel faster, you can use Swoole to accelerate laravel. RELATED Links: https://www.cnblogs.com/cj8988/p/9506606.html


2, the kernel Limit number modification

Ulimit-n default is 1024, modify the larger

Sudo vim /etc/security/limits.conf

Add two lines

* soft nofile 655360
* hard nofile 655360

3. Client link Information

Current number of links Netstat-nat|grep established|wc-l

Server Processing Task Information Netstat-n | awk '/^tcp/{++y[$NF]} END {for (w in y) Print W, y[w]} '

View Client IP link number netstat-nat|grep "tcp" |awk ' {print$5} ' |awk-f: ' {print$1} ' |sort|uniq-c|sort-rn


Solve a lot of time_wait problems

Modify configuration file
Sudo vim /etc/sysctl.conf

Add to

Net.ipv4.tcp_syncookies = 1
Net.ipv4.tcp_tw_reuse = 1
Net.ipv4.tcp_fin_timeout = 30

Net.ipv4.ip_local_port_range = 10240 60999
Net.ipv4.tcp_keepalive_time = 1200
Net.ipv4.tcp_max_syn_backlog = 8192
Net.ipv4.tcp_max_tw_buckets = 5000

Then sudo /sbin/sysctl -p makes the parameters take effect;

Parameter explanation * * *

Net.ipv4.tcp_syncookies = 1 means to enable SYN Cookies. When the SYN wait queue overflow occurs, cookies are enabled for processing, which can prevent a small number of SYN attacks. The default is 0, indicating that it is closed.

Net.ipv4.tcp_tw_reuse = 1 means to enable re-use. Allows TIME-WAIT sockets to be reused for new TCP connections. The default is 0, which means it is off.

Net.ipv4.tcp_fin_timeout=30 Modify the system default TIMEOUT time.

Net.ipv4.tcp_keepalive_time = 1200
# indicates the frequency at which TCP sends keepalive messages when keepalive is enabled. The default is 2 hours and changed to 20 minutes.

Net.ipv4.ip_local_port_range = 1024 65000
# indicates the range of ports used for outgoing connections. By default it is very small: 32768 to 61000, changed to 1024 to 65000.

Net.ipv4.tcp_max_syn_backlog = 8192
# indicates the length of the SYN queue. The default is 1024. The extended queue length is 8192, which can accommodate more network connections waiting for connection.

Net.ipv4.tcp_max_tw_buckets = 5000
# indicates that the system keeps the maximum number of TIME_WAIT sockets at the same time. If this number is exceeded, the TIME_WAIT socket will be cleared immediately and a warning message will be printed.
The default is 180000, which is changed to 5000. For Apache, Nginx and other servers, the parameters of the last few lines can reduce the number of TIME_WAIT sockets very well, but for Squid, the effect is not great. This parameter controls the maximum number of TIME_WAIT sockets, preventing the Squid server from being dragged by a large number of TIME_WAIT sockets.

4, PHP open Opcache (php7.1)

Change setting   
Sudo vim /etc/php/7.1/fpm/php.ini
Found [opcache]
amend as below

[opcache]
; switch on
Opcache.enable=1

; Open CLI
Opcache.enable_cli=1

; available memory, as appropriate, in: Mb
Opcache.memory_consumption=528

Zend Optimizer + Total memory of strings in the scratch pool. (Unit: MB)
; opcache.interned_strings_buffer=8

; For multi-cache file restrictions, if the hit rate is less than 100%, you can try to increase this value.
Opcache.max_accelerated_files=10000

; Opcache will check the modification time of the file within a certain period of time, here set the time period of the check, the default is 2, the positioning is second
Opcache.revalidate_freq=1 (production environment, code can be turned off 0)

Opcache.validate_timestamps=60 //How many seconds to update the php file (production environment, the code can be turned off 0)

Open fast close, open this will speed up the memory recovery when PHP Request Shutdown
Opcache.fast_shutdown=1

* * * * *: When Opcache.revalidate_freq and Opcache.validate_timestamps are set to 0 o'clock, the modified code must be restarted php-fpm for the new code to take effect. (Use command sudo service php7.1-fpm reload)


PHP Performance Optimization---laravel performance optimization

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.