设为首页 收藏本站
查看: 613|回复: 0

[经验分享] php缺点

[复制链接]

尚未签到

发表于 2017-3-3 09:14:36 | 显示全部楼层 |阅读模式
  http://www.bitstorm.org/edwin/en/php/
What I don't like about PHP
  Edwin Martin<edwin@bitstorm.org>.
  Published: August 6th, 2004; Last update: November 26th, 2009.

  I have been developing in PHP since 2001. PHP is very easy to program in.But PHP also has some serious flaws.
  Below I give some reasons why you have to do some serious thinking before implementing a large scale web application in PHP.
1. Bad recursion
  Recursion is the mechanism in which a function calls itself. This isa powerful feature which can make something complex something simple.An example of a function using recursion is quicksort. Unfortunately, PHP is not good at recursion. Zeev, one or the developers of PHP, says this: "PHP 4.0 (Zend) uses the stack for intensive data, rather than usingthe heap.  That means that its tolerance recursive functionsis significantly lower than that of other languages."See bug 1901. This is a poor excuse. Every programming language should provide good recursion support.
2. Many PHP-modules are not thread safe
  A couple of years ago, Apache released version 2.0of its web server.This version supports multithreaded mode, in which one piece ofsoftware can run multiple times simultaneously.The makers of PHP say that the core of PHP is thread safe, only thenon-core modules often aren't.But nine out of ten times, you do want to use such a module in yourPHP-script, making your script unsuitable for Apache's multithreadedmode.And according to some, even the core of PHP isn't thread safe.So it is no surprise the PHP Group doesn't recommend running PHP on Apache 2 in multithreaded mode.The bad multithreaded mode support of PHP is often seen as the reason Apache 2 still didn't catch on.
  Read the discussion about this on Slashdot: Sites Rejecting Apache 2?.
3. PHP is crippled for commercial reasons
  The performance of PHP can be increased to 500% by using caching [benchmarks]. So why is caching not build into PHP? Because Zend, the maker of PHP is selling its own Zend Acceleratorand of course, they don't want to cannibalize on there own commercial products.
  But there is an alternative: APC.
4. No namespaces
  Suppose someone creates a PHP-module that can read files. One of thefunctions in this module is called read. And someone else's module canread web pages and also contains a function read. Then it is impossibleto use these modules together because PHP will not know which readfunction you want.
  An easy solution to this is namespaces. It was a suggested feature for PHP 5, but unfortunately  it didn't make it.Now, without namespaces, every function has to be prefixed with themodule name, to prevent name collisions. This leads to terrible longfunction names likexsl_xsltprocessor_transform_to_xmlwhich makes code harder to write and read.
  Finally, since version 5.3 PHP has namespaces. Unfortunately, as aslevel seperator, it uses the backslash (\) character, normally used toescape other characters.
5. Non-standard date format characters
  Many programmers are familiar with the date format charactersknown from UNIX and the C programming language. Other programminglanguages adopted this standard, but strangely enough, PHP has its own,completely incompatible date format characters. While in C, "%j" standsfor the day of the year, in PHPthis stands for the day of the month. To make things even more confusing: the function strftimeand the date_formatof Smarty, a PHP templating engine, do use the C/UNIX format characters.
6. Confusing licenses
  You might think PHP is free and all PHP-modulesin the manual are free too. Wrong. For example, if you want to generatea PDF-file from PHP you will find two modules in the manual: PDFor ClibPDF. But both come with commercial licenses. So for every module you use, you have to make sure you agree with its license.
7. Inconsequent function naming convention
  Some function names consist of more than one word.There are three conventions for combining these words:

  • Glued together: getnumberoffiles
  • Separated with underscores: get_number_of_files
  • Camel case: getNumberOfFiles
  Most Languages choose one of these variants. PHP uses all of them.
  For example, it you want to convert special characters to HTML entities, you use the function htmlentities(Words glued together).If you want to do the opposite, you use its little brother function html_entity_decode.For some reason the words are now separated by underscores.Why is this bad? You know there is a function named strpad. Or was itstr_pad? Every time you have to look up what the notation is or waitfor an error to occur.Functions are case insensitive, so for PHP there is no differencebetween rawurldecodeand RawUrlDecode. This is bad too, because both are used and because they look different, they will confuse the reader.
8. Magic quotes hell
  Magic quotes prevents PHP-scripts from SQL injection attacks. That'sokay. But for some reason, you can turn this off in the php.iniconfiguration file.So if you want to write a portable script, you always have to checkwhether magic quotes is turned on or off.So a "feature" to make programming easier, actually makes it morecomplex.
9. Framework seldom used
  A website wihout a framework which grows will eventually become amaintanance nightmare.A framework can make a lot of work easier. The most popular model for aframework is the MVC-model, in which layout, business logic andinteraction with the database are seperated.
  Many PHP web sites don't use the MVC-model. They don't even use a framework. Although some PHP frameworksdo exist and you can also write your own, articles or manuals about PHPdon't say a word about frameworks. While JSP-developers use frameworkslike Strutsand ASP-developers use .Net, it looks like the concept of a framework is largely unknown by PHP developers.
  Update: Zend, the developer of PHP, created a framework Zend PHP Framework. Other frameworks, like CakePHP, CodeIgniterand Symfonyare also getting popular. Only the Zend framework is really object-oriented.
10. No Unicode
  With Unicode it is possible to use every language in the world, forexample Chinese, Arabic and Hebrew. While every other seriousprogramming language supports Unicode for many years, PHP still has a very hard timedealing with this.Unicode is planned for PHP 6, so we still have to wait a long time before PHP supports this trivial feature.
11. Slow
  You think Java is slow? PHP is much slower! See this Computer Language Shootout. So how can PHP be used on all these popular websites with lots of visitors? Because of caching. These sites use memcachedand APCto get performance. It doesn't proof anything about PHP, only that it's cachable.
  Even Rasmus Lerdorf, the creator of PHP, admits this. In this interview from SitePoint, Rasmus is asked about how to make PHP fast. He answeres "Well, you can't".
12. Shared Nothing
  A slow interpreter wouldn't be a big problem if you could solve itby adding a couple of extra servers. How easy is that? PHP doesn't havethreads and you can't share data between different PHP-processes.PHP-supporters call this the "Shared Nothing-architecture". Very smartto sell a shortcoming as an advantage. Just like any other system, youhave to share data and in PHP, you do it through the database. Ismoving this problem to the (already slow) database really the rightsolution? I don't think so.
  A simple PHP script can become less than 100kB. But a single page ina serious system or in a CMS can easily become 15MB (yes: megabytes).For every request, this memory has to be initialized, which takes time.It also limits the number of concurrent connections. If you have 2GBavailable for PHP, you can only have 2000/15 is 133 simultaneousconnections. Not much, really.
  In the SitePoint-interview mentioned above, Rasmus also claims PHP doesn't scale.
  Facebook is a nice case to proof this. Facebook is probably the biggest PHP-site. They have 2.3 billionvisits per month.They also use 30 thousandservers. That's a lot.If you do some calculations, you'll find out, on average, one serverhandles only 104 visits per hour. That's really poor performance.
Conclusion
  PHP has two advantages: it's very easy and it's widely supported bywebhosting companies. But that doesn't make it a good language.
  For very small projects, it can be a nice programming language. Butfor larger and more complex projects, PHP can show its weakness. Whenyou search long enough, you'll find solutions (work arounds) to some ofthe mentioned problems. So when a solution is known, why isn't itfixed? And why are the fixes not mentioned in the manual?
  It's good that an open source language is very populair.Unfortunately, it's not a great language. I hope all problems will besolved once (in PHP 6?) and we will have an open source language that'sopen source andgood.
  Until then, when you start a project larger than five scripted pages, you might also consider C#/ASP.Netor Java/JSPas a better solution. And if you want really good (distributed)performance, you can look at some initiatives which have been poppingup the last couple of years. Just to mention a couple of them: Nginx, Couch DBand Node.js. They all blow existing systems away.
  After I wrote this page, some people informed me about other, similar pages:

  • Experiences of Using PHP in Large Websites
  • I'm sorry, but PHP sucks
  • "PHP in contrast to Perl"
  • I hate PHP
  • PHP Annoyances

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-349499-1-1.html 上篇帖子: 学习PHP 下篇帖子: PHP Log
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表