1
2
3
4
5
6
Performance Comparison of PHP and JSP as Server-Side Scripting Languages
MaterialSource:Notesin Computer Science
Author: Scott Trent;Michiaki Tatsubori; Toyotaro Suzumura;Akihiko Tozawa and TamiyaOnodera
1 Introduction
The dynamic scripting language PHP(PHP Hypertext Preprocessor) has becomeenormously popular for implementing lightweight web applications,and is widely used toaccess databases and other middleware.Apache module popularity surveys performed bySecurity Space in October 2007 indicate that 37%of Apache servers have PHP supportenabled,making it the most popular Apache module by 10 percentage points.Businessesare quickly realizing the powerful combination of a service oriented architectureenvironment with dynamic scripting languages like PHP.However,we believe that thereare still critical performance issues involving PHP which remain to be investigated.
This paper focuses on the use of dynamic scripting languages to implement webserver front-end interfaces.This corresponds with the way that the industry standard webserver performance benchmark SPECweb2005 utilizes PHP and JSP ( JavaServerPages).In this case, scripts are used for the implementation of dynamic page generation,rather than the realization of complex business logic.This contrasts with the traditionaluses of complex JSP-based business logic implementation.While there are numerousstudies on dynamic web content, this paper complements these studies with detailedanalysis focusing on PHP. For example, following the performance study on CGI(Common Gateway Interface) based web servers for dynamic content by Yeager&McGrath back in 1995, researchers and practitioners have been examining theperformance of more recent dynamic Webcontent generation technologies.These works,however, handle application scenarios where servlet front-ends implement relativelycomplexbusiness logic.
Although Warner and Worley discuss the importance of also using PHP withSPECweb2005, to the best of the author’s knowledge, this paper is the first to publish adetailed analysis of SPECweb2005 experimental results using both PHP and JSP. Thedetailed analysis of PHP and JSP performance based on SPECweb2005 offered by thispaper enables designers and implementers of web servers to understand the relativeperformance and through put of different versions and configurations of PHP and JSP.
7
2 Multi-tier Web Server Architecture:Lightweight Front-EndUsing PHP/JSP
Developers typically use PHP to implement a front-end interface to dynamic Webcontent generators,which are combined with web server software and back-end serversto provide dynamic content.The web server directly handles requests for static contentand forwards requests for dynamic content to the dynamic content generator. Thedynamic content generator, supported by back-end servers, executes code which realizesthe business logic of a web site and stores dynamic state. Back-end servers may beimplemented as a straight-forward database, or may be more complex servers handlingthe business logic of the web site. The front-end implementation may vary fromheavy-weight business logic handlers to lightweight clients composing content receivedfrom back-end servers.
This paper focuses on multi-tier web site development scenarios utilizing suchlightweight front-ends, supported by one or more layers o f heavy-weight back-ends.Thisassumption is reasonable when considering Service-Oriented environments where PHPscripts are used to implement a "mash-up"of services provided elsewhere, in addition tothe case of simple web sites such as bulletin boards where PHP scripts are just a wrapperto a database. Within the scenarios described in this paper, the dynamic contentgenerator provides client implementation in addition to page composition. It connects tothe back-end server through a network using either standard protocols such as HTTP orapp lication/middleware-spec ific proto co ls.
JSP technology can be considered an alternative to PHP in implementing suchfront-ends.While it is part of the Java Servlet framework,developers typically use JSP toimplement lightweight front-ends.Both PHP and JSP allow developers to write HTMLembedded code. In fact, although there are language inherent differences between PHPand Java, the use ofPHP scripts and JSP files can be very similar.
The objective of the experiments detailed in this paper is to measure theperformance of lightweight front-end dynamic content generation written in PHP and JSPwith popular web servers such as Apache and Lighttpd. This web server architecturescenario involves users who access a web server with pages written in plain static HTML,as well as JSP and PHP scripts which mix scripting language with HTML code. Theconfiguration assumed within the paper is a typical one,where web server software, suchas Apache,distinguishes between pure HTML, JSP,and PHP respectively with suffixes
8
such as .html, .jsp,and.php.HTML code is directly returned to the requesting end-user’sweb browser,where JSP and PHP pages are respectively parsed by the Tomcat scriptengine and the PHP runtime engine which both provide pure HTML which is forwardedto the end-user on a remote system.A common point between JSP and PHP is thatimplementations which perform well have a dynamically compiled and cached byte code.For example, the Java runtime used by the Tomcat script engine which we used performsmuch better when the Just-in-Time (JIT) compiler is enabled to create efficient cachednative runtime code. Similarly, the Zend PHP runtime we used also performssignificantly better when the Alternative PHP Cache (APC) is enabled, in which APCstores PHP byte codes compiled from the script source code in shared memory for futurere us e.
3 Language Runtime Performance Micro Benchmarking
To understand the difference in performance characteristics between PHP and Javaat the language runtime levelwe compared the following engines using a series of microbenchmark te sts:
-PHP 4.4.7
-PHP 5.2.3
-Java 5 with Just-In-Time(JIT)compilation(IBM J9 VM 1.5.0 Build 2.3)
-Java 5 without Just-In-Time(JIT)compilation(same as above)
The PHP language framework allows developers to extend the language with libraryfunctions written in C. These functions,which are known as "extensions", are thenavailable to be used within PHP scripts. The PHP runtime provides a variety ofextensions for string manipulation, file handling,networking,and so forth.S ince our firstgoal was to understand the performance of the PHP runtime itself,we conducted ourexperiments without the use of extensions.We developed the following microbenc hmarks:
-A quick sort benchmark which sorts 100 integers,
-A Levenshtein benchmark which measures the similarity between two strings of 56charac ter s,
-AFibonacci benchmark which calculates the 15th value in a Fibonacci series withtwo arb itrary starting values.
These PHP benchmarks were implemented entirely with PHP language primitivesand avoided the use of PHP extensions. The Java versions also focused on usinglanguage primitives rather than standard classes.We compared the total run time of
9
如今我们很多朋友做网站都比较多的采用站群模式,但是用站群模式我们很多人都知道要拆分到不同IP段。比如我们会选择不同的服务商,不同的机房,至少和我们每个服务器的IP地址差异化。于是,我们很多朋友会选择美国多IP站群VPS商家的产品。美国站群VPS主机商和我们普通的云服务器、VPS还是有区别的,比如站群服务器的IP分布情况,配置技术难度,以及我们成本是比普通的高,商家选择要靠谱的。我们在选择美国多IP...
Megalayer 商家在开始看到有提供香港服务器、香港站群服务器的时候有介绍过,后来就一直没有怎么关注。但是前几天有看到网友使用到他们家的美国独立服务器问其如何的,但是我没有使用过就不好评论,这不前几天也有介绍到Megalayer美国独立服务器。以及我们也有看到商家有提供美国站群服务器和美国大带宽服务器产品,可选30M不限制流量CN2优化线路,以及100M不限制流量国际带宽线路。新年元旦后,Me...
妮妮云的来历妮妮云是 789 陈总 张总 三方共同投资建立的网站 本着“良心 便宜 稳定”的初衷 为小白用户避免被坑妮妮云的市场定位妮妮云主要代理市场稳定速度的云服务器产品,避免新手购买云服务器的时候众多商家不知道如何选择,妮妮云就帮你选择好了产品,无需承担购买风险,不用担心出现被跑路 被诈骗的情况。妮妮云的售后保证妮妮云退款 通过于合作商的友好协商,云服务器提供2天内全额退款,超过2天不退款 物...