如何提高PHP性能?
我已经为 Facebook 创建了 PHP 应用程序。它使用 MySQL、Memcached,并在 Centos 2.6 Ghz 和 2 GB RAM 上的 Lighttpd 上运行。
它基本上是一个 PHP 文件,第一次运行后会被缓存,每次运行时都会在 0.8 毫秒内直接从 Memcached 提供服务。
我还能做些什么来缩短这个时间?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
一旦达到 0.8 毫秒,我不确定是否还能再降低。
但是,您可以设置多个服务器来处理许多并发请求(使用通用的 memcached)。当达到限制时,您只需添加新服务器就可以进行非常高的扩展。
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.
运行 XDebug 并运行分析器。在那里您可以查看是否有任何需要异常时间长度的函数。
我建议使用读取这些日志的程序。就像 kcachegrind 等。
顺便说一句,当你进入分析器国家时,就没有回头路了。
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.
您可以将 http 代理和负载平衡放置到多个服务器。大多数 http 代理可以兼作缓存,从而减轻应用程序的负载。
另外,请确保发送正确的 http 标头,以便您的页面可在客户端缓存。这可能会减少请求数量,因为客户端将重用其缓存的版本。
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.
您是否有一个 php 脚本可以从 memcached 获取数据并显示它们,或者 Web 服务器本身直接从 memcached 获取数据?
我不知道 lighthttpd 是否可以直接从 memcached 显示页面,但我知道 nginx 可以通过 google 搜索 ngx_http_memcached_module
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