Posted on

woocommerce之PHP优化基础

PHP优化基础书:
https://www.sitepoint.com/premium/books/performance-project

1,用Blackfire监控PHP性能问题

PHP-level Performance Optimization with Blackfire:
红色排前面的就是性能问题所在:


2,检查Mysql性能

MySQL Performance Boosting with Indexes and Explain:

show profiles看执行情况:

As we can see, the show profiles; command gives us times not only for the original query but also for all the other queries that are made. This way we can accurately profile our queries.

explain慢查询:



3,用GTmetrix工具检查存在问题

Improving Performance Perception with Pingdom and GTmetrix:
例如:

On-demand Image Resizing 图片加载方面:用srcset


4,后台任务异步化

Using Background Processing to Speed Up Page Load Times

We’re using the Beanstalkd job queue to store jobs, the Symfony Console component to implement workers as console commands and Supervisor to take care of worker processes.

异步的另一个好处:多任务多worker并行处理:
The best part about background processing is the ease of parallel processing. We can set a numprocs=5 directive and Supervisor will spawn five instances of our workers.

利用supervisor:


6,Nginx 和 PHP-FPM方面的优化

Server-side Optimization with Nginx and pm-static
php-fpm :dynamicondemand and static, 尝试 使用:static
https://www.sitepoint.com/server-side-optimization-with-nginx-and-pm-static/
tried the pm = static setting, allowing our PHP processes to take over the maximum of the server’s resources, short of swapping, or driving the CPU to a halt. This setting means we’re forcing the maximum out of our system at all times. It also means that — within our server’s constraints — there won’t be any spawning overhead time cost.


7,页面静态化

Nginx and fastcgi Caching 动态php变成页面静态化


同时也可以使用Cloudflarevarnish