- 浏览: 853819 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
zjhzwx1212:
为什么用threadLocal后,输出值是从20开始的,而定义 ...
j2ee的线程安全--threadlocal -
aeoluspu:
不错 mysql 测试部分感觉不详细
用sysbench(或者super-smack)测试mysql性能 -
nanPrivate:
有没有例子,只理论,实践起来还是不会啊
JMS可靠消息传送 -
lwclover:
一个网络工程师 装什么b
postfix 如何删除队列中的邮件 -
maimode:
我也欠缺不少啊
理想的计算机科学知识体系
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 is a 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 using the heap. That means that its tolerance recursive functions is 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.0 of its web server. This version supports multithreaded mode, in which one piece of software can run multiple times simultaneously. The makers of PHP say that the core of PHP is thread safe, only the non-core modules often aren't. But nine out of ten times, you do want to use such a module in your PHP-script, making your script unsuitable for Apache's multithreaded mode. 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 Accelerator and 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 the functions in this module is called read. And someone else's module can read web pages and also contains a function read. Then it is impossible to use these modules together because PHP will not know which read function 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 the module name, to prevent name collisions. This leads to terrible long function names like xsl_xsltprocessor_transform_to_xml which makes code harder to write and read.
Finally, since version 5.3 PHP has namespaces. Unfortunately, as as level seperator, it uses the backslash (\) character, normally used to escape other characters.
5. Non-standard date format characters
Many programmers are familiar with the date format characters known from UNIX and the C programming language. Other programming languages adopted this standard, but strangely enough, PHP has its own, completely incompatible date format characters. While in C, "%j" stands for the day of the year, in PHP this stands for the day of the month. To make things even more confusing: the function strftime and the date_format of Smarty, a PHP templating engine, do use the C/UNIX format characters.
6. Confusing licenses
You might think PHP is free and all PHP-modules in the manual are free too. Wrong. For example, if you want to generate a PDF-file from PHP you will find two modules in the manual: PDF or 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 it str_pad? Every time you have to look up what the notation is or wait for an error to occur. Functions are case insensitive, so for PHP there is no difference between rawurldecode and 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's okay. But for some reason, you can turn this off in the php.ini configuration file. So if you want to write a portable script, you always have to check whether magic quotes is turned on or off. So a "feature" to make programming easier, actually makes it more complex.
9. Framework seldom used
A website wihout a framework which grows will eventually become a maintanance nightmare. A framework can make a lot of work easier. The most popular model for a framework is the MVC-model, in which layout, business logic and interaction 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 frameworks do exist and you can also write your own, articles or manuals about PHP don't say a word about frameworks. While JSP-developers use frameworks like Struts and 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 , CodeIgniter and Symfony are 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, for example Chinese, Arabic and Hebrew. While every other serious programming language supports Unicode for many years, PHP still has a very hard time dealing 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 memcached and APC to 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 it by adding a couple of extra servers. How easy is that? PHP doesn't have threads and you can't share data between different PHP-processes. PHP-supporters call this the "Shared Nothing-architecture". Very smart to sell a shortcoming as an advantage. Just like any other system, you have to share data and in PHP, you do it through the database. Is moving this problem to the (already slow) database really the right solution? I don't think so.
A simple PHP script can become less than 100kB. But a single page in a 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 2GB available for PHP, you can only have 2000/15 is 133 simultaneous connections. 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 billion visits per month. They also use 30 thousand servers. That's a lot. If you do some calculations, you'll find out, on average, one server handles only 104 visits per hour. That's really poor performance.
Conclusion
PHP has two advantages: it's very easy and it's widely supported by webhosting companies. But that doesn't make it a good language.
For very small projects, it can be a nice programming language. But for larger and more complex projects, PHP can show its weakness. When you search long enough, you'll find solutions (work arounds) to some of the mentioned problems. So when a solution is known, why isn't it fixed? 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 be solved once (in PHP 6?) and we will have an open source language that's open source and good.
Until then, when you start a project larger than five scripted pages, you might also consider C#/ASP.Net or Java/JSP as a better solution. And if you want really good (distributed) performance, you can look at some initiatives which have been popping up the last couple of years. Just to mention a couple of them: Nginx , Couch DB and 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
发表评论
-
php performance tuning site
2010-09-05 08:47 983http://www.perfgeeks.com/ -
php performance
2010-09-01 12:51 554http://talks.php.net/show/digg/ ... -
php benchmark 脚本
2010-09-01 10:59 1189<?php $iterations = 12; $s ... -
程序员小炒
2009-12-27 18:50 1152Design HTML (1 ) ( ... -
开源网店整站系统程序
2009-06-18 14:26 1887开源的网店整站系统程序,是经验电子商务和小商业人士的必然之选。 ... -
Simple Optimization for PHP and MySQL
2009-06-17 13:08 978Here is a list of a few very si ... -
管理php-cgi的好工具php-fpm
2009-03-15 13:22 1640非常好!!! -
php高级资料
2009-02-02 10:26 12091.一个支持PHP的数据库连接池项目SQL Relay ht ...
相关推荐
缺点:每次查杀都需要上传文件到WebDir 并等待返回结果 速度比较慢 需要耐心等待 优点:Api 免费 并且不限制上传文件数量。 WEBDIR+采用先进的动态监测技术,结合多种引擎零规则查杀,低误报、高查杀率。 Html Gui...
然而,PHP也存在一些缺点: 1. **多线程支持不足**:PHP并不擅长处理多线程应用,通常需要通过其他方式模拟实现。 2. **语法不严谨**:PHP的变量无需预定义即可使用,这在某些情况下可能导致错误或难以追踪的问题...
- PHP缺点:安装配置相对复杂、解释执行可能导致运行时错误、灵活性大可能导致不稳定性。 3.PHP环境搭建: - 使用工具如phpStudy,它提供了一键安装的服务器环境,其中"www"目录是存放项目代码的地方。例如,将...
PHP(Hypertext Preprocessor,超文本预处理器...然而,如同任何技术一样,PHP也存在一些不足,如代码组织可能不够严谨,某些功能可能不如其他语言先进,但这些缺点通常可以通过良好的编程实践和持续的版本更新来克服。
本文将讨论PHP常用的七大框架,它们分别是ThinkPHP、Yii2、Laravel、CodeIgniter、Zend Framework、Yaf和Symfony(尽管Symfony未在提供的内容中被提及,但作为较为流行的框架,也包含在讨论范围内),并分析它们各自...
标题和描述中提到的核心知识点是,优秀的PHP程序员需要理解PHP代码的优缺点,这涉及到代码的结构化、规范化、自适应性和安全性。以下是对这些方面更详细的解释: 1. 结构化代码:良好的PHP代码应该遵循模块化和分层...
【标题】:深入探讨ASP、PHP、JSP的优缺点 【描述】:本文将对ASP、PHP和JSP这三种主流的Web开发语言进行详细分析,探讨它们各自的特点、优势、不足以及适用场景,帮助开发者更好地理解这些技术并选择合适的开发...
### 从PHP视角探讨面向对象与面向过程编程的优缺点 #### 一、引言 在软件开发领域,编程范式的选择对项目的成功至关重要。PHP作为一种广泛应用的脚本语言,在Web开发领域尤其受到青睐。本文将从PHP的角度出发,...
【标题】:深入探讨ASP、PHP和JSP的优缺点 【描述】:本文将对ASP、PHP和JSP这三种流行的网站开发语言进行详细分析,揭示它们各自的优点、缺点及适用场景,帮助开发者了解不同语言的特点。 【部分内容】: **ASP ...
【IIS与Apache优缺点详解】 IIS(Internet Information Services)和Apache都是广泛使用的Web服务器,它们各有特色,适用于不同的应用场景。了解它们的优缺点有助于我们更好地选择适合自己的Web服务解决方案。 **...
Java、C#、PHP是三种广泛使用的编程语言,它们各自有着独特的优缺点,适用于不同的应用场景。下面将分别探讨这些语言的特性和优缺点。 Java: 1. 面向对象:Java是一种完全面向对象的编程语言,允许开发者创建类和...
安装快速,易于使用,特别是在Web应用程序中,与PHP等语言配合良好。 - **缺点:** 对于大数据量和复杂事务处理的能力相对较低。在高级功能和企业级服务方面,可能不如其他商业数据库强大。 在选择数据库时,需要...
【标题】:主流的网站开发语言优缺点-ASP、JSP、PHP 三种技术比较 【主要内容】: 网站开发语言的选择对于构建高效、安全且可扩展的web应用程序至关重要。本文将对比分析三种主流的Web开发语言:ASP、JSP和PHP。 ...
本文将对几款当前流行的PHP框架进行优缺点对比分析,帮助开发者选择更适合自己的开发工具。 【CodeIgniter】 CodeIgniter以其轻量级、简洁易用的特点著称。其优点在于: 1. 配置简单,使用PHP脚本配置,提高了...
【PHP生成EXE软件】 ...在使用这类工具时,开发者应全面了解其优缺点,合理利用其优势,同时注意防范潜在风险。对于想要学习或使用这一技术的PHP程序员来说,了解相关知识并掌握其用法是至关重要的。
这样做的好处是程序可以在没有预装PHP的系统上运行,但缺点是程序可能会很大,且更新PHP版本时需要重新编译整个程序。 2. **动态链接库**:另一种方法是使用动态链接库(如libphp5.so),这样可以减小程序的体积。...