# 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](http://kr.github.io/beanstalkd/)?job queue to store jobs, the Symfony Console component to implement workers as console commands and?[Supervisor](http://supervisord.org/)?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 :`dynamic`,?`ondemand`?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變成頁面靜態化


同時也可以使用**Cloudflare** 和 **varnish**。