PHP Performance Optimization---laravel performance optimization

Source: Internet
Author: User

Tags: Allow opera color accelerator file time_wait Service squid use

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:

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 config file sudo vim/etc/sysctl.conf add net.ipv4.tcp_syncookies = 1net.ipv4.tcp_tw_reuse = 1net.ipv4.tcp_fin_timeout = 30net.ipv4.ip_local_port_range = 10240 60999net.ipv4.tcp_keepalive_time = 1200net.ipv4.tcp_max_syn_backlog = 8192net.ipv4.tcp_max_tw_buckets = 5000 then  sudo  /sbin/sysctl-p   Let the parameters take effect.

Parameter explanation * * *

Net.ipv4.tcp_syncookies = 1 means that Syn Cookies are turned on. When a SYN wait queue overflow occurs, cookies are enabled to protect against a small number of SYN attacks, the default is 0, which means close; Net.ipv4.tcp_tw_reuse = 1    means turn on reuse. Allows the time-wait sockets to be re-used for new TCP connections, which defaults to 0, which means close; net.ipv4.tcp_fin_timeout=30    modifies the default timeout time for the system. Net.ipv4.tcp_keepalive_time = #表示当keepalive起用的时候, the frequency at which TCP sends keepalive messages. The default is 2 hours, which is changed to 20 minutes. Net.ipv4.ip_local_port_range = 1024x768 65000 #表示用于向外连接的端口范围. Small by default: 32768 to 61000, 1024 to 65000. Net.ipv4.tcp_max_syn_backlog = 8192 #表示SYN队列的长度, with a default of 1024, and a larger queue length of 8192, which can accommodate more network connections waiting to be connected. Net.ipv4.tcp_max_tw_buckets =  5000# indicates that the system maintains the maximum number of time_wait sockets at the same time, and if this number is exceeded, the time_wait socket is immediately cleared and a warning message is printed. The default is 180000, which changes to 5000. For Apache, Nginx and other servers, the parameters of the last few lines can be a good way to reduce the number of time_wait sockets, but for Squid, the effect is not small. This parameter controls the maximum number of time_wait sockets, preventing squid servers from being dragged to death by a large number of time_wait sockets.


4, PHP open Opcache (php7.1)

  modify configuration sudo vim/etc/php/7.1/fpm/php.ini find [Opcache] modify as follows [Opcache]; switch opens opcache.enable=1 ; Open Cliopcache.enable_cli=1 ; Available memory, as appropriate, in units: Mbopcache.memory_consumption=528 ; Zend Optimizer + The total memory of the string in the staging pool. (unit: MB); opcache.interned_strings_buffer=8 ; For multi-cache file limit, hit less than 100%, you can try to increase this value opcache.max_accelerated_files=10000 ; Opcache will check the file modification time within a certain time, here set the check time period, the default is 2, positioning for seconds opcache.revalidate_freq=1 (production environment, The code does not change can be closed 0)  opcache.validate_timestamps=60//How many seconds to update the PHP file (production environment, the code is not changed can be closed 0) ; Turn on quick close to open this shutdown the speed of reclaiming memory in PHP Request is increased 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

Related Article

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: and provide relevant evidence. A staff member will contact you within 5 working days.

Tags Index: