为什么PHP适用于高流量网站? [英] Why is PHP apt for high-traffic websites?

查看:65
本文介绍了为什么PHP适用于高流量网站?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天,我惊讶地发现PHP被广泛用于高流量的网站.

I was surprised to learn today that PHP is used widely in high-traffic websites.

我一直认为PHP是一种动态的脚本语言(例如,与诸如C/Java/C#等静态类型的编译语言相比)在性能方面并不强.

I always thought that PHP is not strong in terms of performance, being a dynamic, scripting language (e.g. compared to statically typed, compiled language like C/Java/C# etc.).

那么它的表现如何如此好呢?

So how come it performs so well?

推荐答案

您通常会发现它的运行速度没有您想象的那么慢.许多站点运行缓慢的原因是主机过载.

What you'll usually find is that it's not as slow as you think. The reason a lot of sites are slow is because the hosts are overloaded.

但是与编译语言相比,PHP的一个主要优点是易于维护.由于PHP是专为HTTP流量而设计的,因此与大多数其他编译语言相比,构建起来更少.另外,合并更改变得更加容易,因为您不需要重新编译和重新启动服务器(就像使用已编译的二进制文件一样)...

But one primary benefit of PHP over a compiled language is ease of maintenance. Because PHP is designed from the ground up for HTTP traffic, there's less to build than with most other compiled languages. Plus, merging in changes becomes easier as you don't need to recompile and restart the server (as you would with a compiled binary)...

我在这两个方面都做了相当多的基准测试,对于每秒约5万个请求(根据我的数字)的任何地方,使用编译二进制(FastCGI)确实不会有很大的收益.当然,使用编译后的C会更快一些,但是除非您在谈论Facebook级别的流量,否则这并不意味着真正的$$$.而且与使用C相比,它绝对不会抵消PHP所能提供的相对较快的开发速度(由于它不是由内存管理的,因此很可能需要很多倍的代码)...

I've done a considerable amount of benchmarks on both, and for anywhere under about 50k requests per second (based upon my numbers) there really isn't a significant gain to using a compiled binary (FastCGI). Sure, it's a little faster using compiled C, but unless you're talking Facebook level traffic, that's not really going to mean significant $$$. And it's definitely not going to offset the relatively rapid rate of development that PHP will afford in comparison to using C (which more than likely will require many times the code since it's not memory managed)...

如果编写得当,PHP可以具有很好的可扩展性.限制因素通常在数据库引擎中.无论您使用哪种技术,这都将是一个普遍因素...

PHP, if properly written can be quite scalable. The limiting factors are typically in your database engine. And that's going to be a common factor no matter what technology you use...

这篇关于为什么PHP适用于高流量网站?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆