How to improve PHP performance?

2020-06-23 09:12发布

问题:

I've created PHP application for Facebook. It uses MySQL, Memcached and works on Lighttpd on Centos 2,6 Ghz and 2 GB RAM.

it's basically one PHP file that after first run is cached and every next time it's served in 0,8 ms directly from Memcached.

What more can I do to shorten this time?

回答1:

Once you get to 0.8 ms, I'm not sure you can go any lower.

However, you can set up multiple servers to handle many concurrent requests (with a common memcached). You will then be able to scale very high by simply adding a new server when you reach limits.



回答2:

Run XDebug and run the profiler. There you can see if you have any functions that take an abnormal length of time.

I recommend using a program that reads those logs. Like kcachegrind etc.

BTW, when you enter profiler country, there's no turning back.



回答3:

You can put a http-proxy and load balance to multiple servers. Most http-proxies can double as a cache, which can take load off the application.

Also, make sure that you send the proper http headers, so that your pages are client-side cacheable. This may reduce the number of requests, as the clients will reuse their cached version.



回答4:

Do you have a php script which gets data from memcached and displays them, or the web server itself gets data, directly from memcached?

I don't know if lighthttpd can display page directly from memcached, but i know nginx can do this google for ngx_http_memcached_module