Using PHP And ASP Abstract

Transcription

A Comparison Study of Web Based Application DevelopmentUsing PHP and ASP.NETMorris M. Liaw, Ph. D.Univ. of Houston Clear LakeHouston, TX 77058, USliaw@uhcl.eduAbdul Mansoor Mohammed.Univ. of Houston Clear LakeHouston, TX 77058, USinform.mansoor@gmail.comdevelopers of ASP.NET and PHP assuretheir users that both platforms are capable offulfilling their web application needs,ASP.NET requires the support of a muchlarger development community. Why this isthe case is worth investigating since bothlanguages have been utilized in creatingvery large and very successful webapplications.Abstract:This paper takes a detailed look at PHP, anopen source server-side scripting language,and compares it to its heavily marketedcounterpart ASP.NET. It explores variousconcepts which are pertinent to choosingprogramming platforms and outlines theadvantages of each language over the other.A sample application called “PersonalMedia Center” is developed in PHP toillustrate these concepts and advantages, anda summary of the factors which affect theusability of both platforms is discussed atthe conclusion of this paper.2. Brief Review of PHP:As mentioned earlier, PHP is primarilyfocused on server-side scripting capabilitiesto provide programmers with the necessarytools for creating web applications that areheavily dynamic in nature. It is capable ofperforming all the actions of any CGIprogram and has a vast array offunctionalities, e.g. collecting form data,generating dynamic web pages, and settingand accessing cookies for session control.The primary functionalities of PHP, asstated by its developers, are server-sidescripting, command line scripting, anddesktop applications. It can be used on allmajor operating systems, including UNIXand Linux, and thus, gives web developers achoice of operating system and web serverwhen deploying an application.Anotherstrong and significant feature of PHP is itsability to support various databases. Adatabase enabled web page can be writtenwith incredible simplicity using eitherKeywords: PHP, MySQL, Web ApplicationPlatform, ASP.NETAcknowledgement:Very special thanks to Matthew E.Liaw (gordongartrell@gmail.com), StanfordUniversity for proof reading the content ofthis paper.1. Introduction:When developing a web application that hasserver-side scripting capabilities, the naturalchoice for a programmer today would beone of the two most widely used scriptinglanguages, namely Microsoft s ASP.NETand/or open source PHP. Though the1

database specific extensions for MySQL orabstraction layers like PDO [PHP DatabaseObjects].The following sectionapplication in more detail.discussesthe3. About Personal Media Center:Based on a 2007 Netcraft survey, 54.9%[112,945,968] of 205,714,253 websites werehosted on Apache HTTP Servers whereas25.9% [53,217,620] were hosted onWindows Servers. This information appearsto indicate that PHP is a far more popularplatform than ASP.NET for web-applicationdevelopers. Figure 1 shows the statistics forthis survey.[1]The proposed functionalities of PersonalMedia Center are those of a websitedesigned primarily to host different types ofmedia such as pictures, music, and videoswhich can be remotely uploaded by thewebsite’s administrator. Subscribers andvisitors from all over the world will able toview this media, and registered users will beable to discuss and post comments about themedia in a manner akin to other socialnetworking websites. Users will also be ableto register for updates and newsletters sentout by the administrator.Since we will be looking at PHP from theperspective of an entry level programmer,we will only establish and verify its basicfunctionalities. We do this by developing asimple 3-tier website called Personal MediaCenter.2

The performance of PHP is put to the test byusing it to dynamically manipulate the entirewebpage s text into either SimplifiedChinese or English based on the user schoice of language.The application uses the cookie functions inPHP API to execute these authenticationmechanisms. There is a single interface forall users, but the rights are based on theuser’s login credentials. This fully functionalapplication is deployed on the DCM(Division of Computing and Mathematics)server at the University of Houston-ClearLake and can be tested at the following link.The application is designed with PHPtechnology to run on a web server runningApache Tomcat 6.0 and extensively usesMySQL 5.5 for all database-relatedoperations. Although any viewer with aninternet connection has the ability to browsecontent on the website, only theadministrator has the right to upload mediato it. Additionally, only registered users willbe able to comment on the 2.0/The following figures show screenshots ofpages on the Personal Media Centerapplication website. Figure 2(a) shows thehome page of the application, and Figure 2(b)shows the gallery page of the website whichserves as the root page for browsing allmedia.3

For the Personal Media Center application,there are three types of users as mentionedbelow. Each class of user has a differentlevel of access, with the administratorhaving the highest level and casual usershaving the lowest level of access controlrights.4. Using PHP for Applications:One of the biggest advantages of using PHPwhen creating web applications is that PHPscripts can be embedded directly into HTMLpages. During the initial development phaseof the Personal Media Center application, astatic HTML website was designed usingcommon HTML and various text editors.PHP scripts and actions were embedded intothe HTML pages later on which helped tosimplify the development process byseparating interface development fromfunctional implementation.1. Administrator2. Registered users3. Casual viewersFigure 3 below is a simple flow chart ofactions for the administrator of theapplication. Some of the additional functionsnot mentioned in the above chart can befound in the application but have beenomitted for the sake of brevity.4

The major components of functionality froman administrator’s perspective are uploadingand managing media. The followingsnippets of code in Figures 4(a) and 4(b)show the PHP functions used to upload anddeletefiles,respectively.move uploaded file takes the path of the fileEach function call follows the sequence ofactions below:1. Check the user-set cookie forlanguage preference; if none isfound, set the cookie to Englishas the default preference.2. Look up the phrase in thedictionary of defined phrases.3. Return the phrase in thecorresponding language found inthe cookie.to be uploaded and the future path of the fileat the server as arguments and moves the fileto the server, thus completing the upload.unlink [2] takes the path of the file andsimply deletes it from the server.Currently, this may not be the bestimplementation of a translation function asone must specify each and every phrase inthe dictionary. However, the translationfunction plays a key role in testing PHP’sability to handle large numbers of functioncalls from a specific client request. Asnippet from the translation dictionary isshown in Figure 5(a).As mentioned previously, a translationfunction built into the application can beused to test the performance of PHP. Thefunction is able to translate the text withinPersonal Media Center by using a staticdictionary of user-defined terminology.The translation function is called for eachand every text phrase in all of the pages ofthe website.5

5. Using MySQL:6. Conclusion:All database-related back-end operations forPersonal Media Center were done usingMySQL. An important reason for choosingMySQL as a database back-end was PHP’sbuilt-in support for it. The MySQL querygenerator in PHP is very useful in theformulation and testing of queries.The development of Personal Media Centershows that PHP has several advantages overMicrosoft’s ASP.NET. The followingcrucial factors were analyzed to reach thisconclusion(i) Cost: When compared to ASP.NET,PHP leads in this area because it isfree, and no additional licensing feeis required to use it. Each member ofthe PHP suite, known collectively asLAMP (Linux, Apache, MySQL,and PHP), is also free, with supportand upgrades provided at no extracost. On the other hand, licensingMicrosoft’s server software can costover 1000. This makes LAMP avery popular platform for e functions open and close are notrequiredforopeningandclosingconnections to MySQL servers. Aconnection initialization, query declaration,and execution request is shown in thesnippet of code in Figure 6(a).The result set of a select query is stored inthe requesting variable and can be accessedas shown in Figure 6(b).6

(ii) Performance: When the performanceof the programming language isconsidered alone irrespective ofdatabase engine used, PHP has anadvantage over ASP.NET because itis known for running “lightly” onservers and is free of any unneededpackages. The lack of GUI’s alsogives PHP servers an extra edge inperformance.7. References:[1]Web Resource: www.php.net[2]Murach, Joel, and Ray Harris. Murach'sPHP and MySQL: Training & Reference. [Fresno,Calif.]: Mike Murach & Associates, 2010. Print.[3] Kohan, Bernard. "PHP vs ASP.netComparison." PHP vs ASP.net PerformanceComparison. Bernard Kohan. Web. 20 Mar.2012. tml .(iii)Complexity:Taskscanbeaccomplished with far fewer lines ofcode in PHP than in ASP.NET.Though coding outside of HTMLpages may initially appear tosimplify the development process,having to map related code betweenseparate files when using ASP.NETrequiresahighlevelofunderstanding which can act as anobstacletomorenoviceprogrammers. It is no mystery thenwhy PHP has become very popularwith beginners.[4]Web Resource For Zend:[http://www.zend.com/en/]Future studies will explore why the .NETframework is still popular with manydevelopers, despite several advantagesassociated with PHP and the LAMPsoftware suite.7

Using PHP and ASP.NET Morris M. Li aw, Ph. D. Univ. of Houston Clear Lake Houston, TX 77058, US liaw@uhcl.edu Abdul Mnsoor oh med. Univ. of Houston Clear Lake . and Ray Harris. Murach's PHP and MySQL: Training & Reference. [Fresno, Calif.]: Mike Murach & Associates, 2010. Print. [3] Kohan, Bernard. "PHP vs ASP.net C o mpari s n." PHP v ASP .