Tải bản đầy đủ - 0 (trang)
Appendix D. Power and Speed: CGI and mod_perl

Appendix D. Power and Speed: CGI and mod_perl

Tải bản đầy đủ - 0trang

Today,ApacheisthemostpopularWebserverontheInternet,

andmod_perlisoneofthemostpopularmodulesforextending

it.Withthemod_perlAPI,itispossibletowritecustomized

ApachemodulesinPerlratherthaninCandtodynamically

configuretheserveritself,makingtheadministrationofservers

withcomplexconfigurationseasiertomanage.Youcanwrite

authenticationandauthoriztionhandlerstoalloworrestrict

usageofcertainpages,performdatabaselookups,rewriteHTTP

requestsandURLs,logrequests,etc.

Bundledwithmod_perlaretwogeneral-purposemodulesthat

makeitpossibletorunexistingPerlCGIscriptswithout

modification(aslongastheyarewellwritten,not"sloppy").

ThesePerlmodulesarefoundinthePerlsite/liblibrary;they

arecalledApache::Registry.pm(orModPerl::Registry.pm)and

Apache::PerlRun.pmor(ModPerl::PerlRun.pm).Thedifference

betweenthesetwomodulesisthattheRegistry.pmmodule

cachesallscripts,andthePerRun.pmmoduledoesn't.The

advantageofcaching(i.e.,compilingthescriptonceand

keepingitinmemory)isspeedandpersistence.Thisisallfine

aslongasthescriptiswell-written,hasinitializedvariables,

closedfilehandles,setswarningsanddiagonostics,and

generallyfollowsrulesofgoodPerlprogramming.Ifthescriptis

writteninasloppyway,thenthePerlRun.pmmoduleisasafer

choice.Eachtimearequestismadeforthescript,everything

startsfreshbecausethecodewasnotcached.Eitherway,the

bigadvantageisthatthePerlinterpreterisloadedonlyonce,

therebyincreasingtheperformanceofyourscripts.The

mod_perlsite(http://perl.apache.org/download/index.html)

saysthat"thestandardApache::Registrymodulecanprovide

100xspeedupsforyourexistingCGIscriptsandreducetheload

onyourserveratthesametime."

Checkthissiteforstatisticsonmod_perlandApacheusage

worldwide.

FigureD.1.

[Viewfullsizeimage]



AppendixD.PowerandSpeed:CGIand

mod_perl

WhatIsmod_perl?

Themod_perlWebSite

Installingmod_perl

Resources



D.1.WhatIsmod_perl?

SomepeoplemaytellyouthatCGIscriptsareathingofthe

past.YoushouldbeusingPHP,ASP.NET,etc.Nottrue.The

mod_perlmodule(originallywrittenbyDougMacEachernand

licensedundertheApacheSoftwarelicense)givesyouawhole

newwaytocreatedynamiccontentbyintegratingtheApache

serverandPerl.mod_perlisdescribedasthemarriagebetween

ApacheandPerl.Itisanopensourcemoduleimplementedasa

PerlinterfacetotheApacheAPIandallowsexistingCGIscripts

torunmuchfaster.

ByembeddingthePerlinterpreterrightintheApacheserver,

thereisnoneedtostartup(fork)aseparate,external

interpretertorunCGIprograms.Inaddition,modulesand

scriptsareloadedandcompiledonlyonce,andfortherestof

theserver'slifetheyareservedfromthecache.Thus,the

serverspendsitstimerunningalreadyloadedandcompiled

code,whichisveryfast.

LincolnStein,authorofCGI.pm,describesmod_perlasfollows:

"mod_perlismorethanCGIscriptingonsteroids.Itisa

wholenewwaytocreatedynamiccontentbyutilizingthe

fullpoweroftheApachewebservertocreatestateful

sessions,customizeduserauthenticationsystems,smart

proxiesandmuchmore.Yet,magically,youroldCGIscripts

willcontinuetoworkandworkveryfastindeed."



Today,ApacheisthemostpopularWebserverontheInternet,

andmod_perlisoneofthemostpopularmodulesforextending

it.Withthemod_perlAPI,itispossibletowritecustomized

ApachemodulesinPerlratherthaninCandtodynamically

configuretheserveritself,makingtheadministrationofservers

withcomplexconfigurationseasiertomanage.Youcanwrite

authenticationandauthoriztionhandlerstoalloworrestrict

usageofcertainpages,performdatabaselookups,rewriteHTTP

requestsandURLs,logrequests,etc.

Bundledwithmod_perlaretwogeneral-purposemodulesthat

makeitpossibletorunexistingPerlCGIscriptswithout

modification(aslongastheyarewellwritten,not"sloppy").

ThesePerlmodulesarefoundinthePerlsite/liblibrary;they

arecalledApache::Registry.pm(orModPerl::Registry.pm)and

Apache::PerlRun.pmor(ModPerl::PerlRun.pm).Thedifference

betweenthesetwomodulesisthattheRegistry.pmmodule

cachesallscripts,andthePerRun.pmmoduledoesn't.The

advantageofcaching(i.e.,compilingthescriptonceand

keepingitinmemory)isspeedandpersistence.Thisisallfine

aslongasthescriptiswell-written,hasinitializedvariables,

closedfilehandles,setswarningsanddiagonostics,and

generallyfollowsrulesofgoodPerlprogramming.Ifthescriptis

writteninasloppyway,thenthePerlRun.pmmoduleisasafer

choice.Eachtimearequestismadeforthescript,everything

startsfreshbecausethecodewasnotcached.Eitherway,the

bigadvantageisthatthePerlinterpreterisloadedonlyonce,

therebyincreasingtheperformanceofyourscripts.The

mod_perlsite(http://perl.apache.org/download/index.html)

saysthat"thestandardApache::Registrymodulecanprovide

100xspeedupsforyourexistingCGIscriptsandreducetheload

onyourserveratthesametime."

Checkthissiteforstatisticsonmod_perlandApacheusage

worldwide.

FigureD.1.

[Viewfullsizeimage]



D.2.Themod_perlWebSite

Thefollowingtopicsarediscussedatthemod_perlhomepage

andwillgiveyoueverythingyouneedtoknowaboutmod_perl,

includinginstallation,downloads,documentation,help,bugs,

etc.Asynopsisofthissiteisshownhere.



WhatIsmod_perl?



mod_perlisthemarriageofApacheandPerl.

mod_perlbringstogethertwoofthemostpowerfulandmaturetechnologie

mp2ismod_perlforthe2.x.xbranchoftheApacheHTTPDServer.

mp1ismod_perlforthe1.3branchoftheApacheHTTPDServer.



mp2isfullycompatiblewithHTTPD2.0.xandsupportsmostofthe2.2.xfe

mod_perl'sfutureplansaretokeeponsupportingHTTPDasitevolves

—thathas

alwaysbeenthegoalandwillalwaysbeso.

Simplyinstallmod_perlandyouhavethefullpowerofthe

ApacheWebServeratyourfingertips.



SuccessStories

mod_perlisthepowerbehindmanyoftheInternet'sbusiest

andmostadvancedWebsites.Listedherearesuccessstories

frompeopleusingmod_perl;also,worldwidestatisticsof

mod_perlusage.



Download

Getsourceandbinarymod_perldistributionsanddownloadthe

documentation.



Documentation

Themod_perlprojectfeaturesalotofdocumentation,forboth

mod_perl1.0and2.0.Ifthereisanythingyouneedtolearn



aboutmod_perl,you'lllearnithere.



ReportingBugs

Beforeabugcanbesolved,developersneedtobeableto

reproduceit.Usersneedtoprovidealltherelevantinformation

thatmayassistinreproducingthebug.However,it'shardto

knowwhatinformationneedstobesuppliedinthebugreport.

Inordertospeeduptheinformationretrievalprocess,wewrote

theguidelinesexplainingexactlywhatinformationisexpected.

Usually,thebetterthebugreportis,thesoonerit'sgoingtobe

reproducedandthereforefixed.



GettingHelp

Solveyourmod_perlproblems:withthehelpofthemod_perl

mailinglists,amod_perltrainingcompany,oracommercial

supportcompany.FindanISPprovidingmod_perlservices.



MailingLists

mod_perlandrelatedprojects'mailinglists.



Products

Thereisalotofsoftwareouttherereadytorunwithmod_perl

and/orhelpyouwithyourprogrammingproject.



Contribute

Howtocontributetothemod_perlcommunity.



Gotmod_perl?

Advocacydocumentsandresourcesformod_perl.



Aboutmod_perl

Generalinformationregardingmod_perlofhistoricalinterest.



mod_perlSubprojects



Otherprojectsmaintainedunderthemod_perlumbrella.



Jobs

Findthemod_perljobofyourdreams!



SiteMap

Youcanreachanydocumentonthissitefromthissitemap.



D.3.Installingmod_perl

Thissectiondescribesthegeneralseriesofstepsusedtoinstall

mod_perlandconfigureApachetouseitforexecutingfastCGI

scripts.YoushouldalreadyhaveacurrentversionofPerland

ApacheupandrunningandhavesomefamiliaritywithhowCGI

works(seeChapter16).

Theexamplesdemonstratehowtoinstallandrunmod_perl

scriptsonaWindowssystemusingApache2.xand

ActivePerl5.8.8.

Fordocumentation,gotothemod_perlsite,

http://perl.apache.org/docs/index.html.Togetsourceand

binarymod_perldistributions,gotothedownloadpageat

http://perl.apache.org/download/index.html.Configuringthe

Apachehttpd.conffilemayhavesomedifferencesduetothe

factthatthePerlmodulesrequiredarenotnecessarilylocated

inthesamelibrary.Ittooksometimetofigureouthowto

adaptthistothecurrentversionsofApacheandPerlbeingused

here.

Therearetwoversionsofmod_perl:

mp2—mod_perlforthe2.x.xbranchoftheApacheHTTPD

Server.

mp1—mod_perlforthe1.3branchoftheApacheHTTPD

Server.

Forthisexample,wewillbeusingmp2isfullycompatiblewith

HTTPD2.0.x,andsupportsmostofthe2.2.xfeatureset.



Installingmod_perlforActiveStatewithPPM

Installationofmoduleshasbecomeincreasinglysimplifiedwith

ActiveState'sPPMtool.ItisincludednowwitheveryActivePerl

releasefornotonlyWindowsbutalsoUNIX/Linuxversonsof

ActivePerl.Thistoolallowsyoutoinstall,remove,upgrade,and



otherwisemanagetheuseofcommonPerlpre-compiledCPAN

modules.

ThefollowingexamplesusePPMonaWindowssystem.

ExampleD.1.

CodeView:



C:\>ppminstallmod_perl

DownloadingActiveStatePackageRepositorypacklist...done

UpdatingActiveStatePackageRepositorydatabase...done

ppminstallfailed:Can'tfindanypackagethatprovidemod_per



C:\>ppminstallhttp://theoryx5.uwinnipeg

/ppms/mod_perl-2.0.ppd

Downloadingmod_perl-2.0-2.0.3...done

Unpackingmod_perl-2.0-2.0.3...done

GeneratingHTMLformod_perl-2.0-2.0.3...done

Updatingfilesinsitearea...done

Downloadingmod_perl-2.0-2.0.3installscript...done

Runningmod_perl-2.0-2.0.3installscript...

TheApachemodulemod_perl.soisneededtocompletetheinstall

andshouldbeplacedinyourApache2modulesdirectory.Iwill

nowfetchandinstallthisforyou.



Fetchinghttp://theoryx5.uwinnipeg.ca/ppms/x86/mod_perl-2.0.so

done!

Whereshouldmod_perl.sobeplaced?[C:/Apache2/modules]

c:/wamp/Apache2/modu



mod_perl.sohasbeensuccessfullyinstalledtoc:/wamp/Apache2/

done

465filesinstalled

























Apache'sconfDirectory(ConfigurationFiles)



ExampleD.2.

cdc:\wamp\Apache2\conf

C:\wamp\Apache2\conf>dir/b

alias

httpd.conf

httpd.default.conf

magic

magic.default

mime.types

mime.types.default



EditingApache'shttpd.confFile

TheApachehttpd.conffilethenmustbemodifiedbyaddingthe

followingline:

ExampleD.3.

CodeView:

#LoadModulemime_magic_modulemodules/mod_mime_magic.so

#LoadModuleproxy_modulemodules/mod_proxy.so

#LoadModuleproxy_connect_modulemodules/mod_proxy_connect.so

#LoadModuleproxy_http_modulemodules/mod_proxy_http.so

#LoadModuleproxy_ftp_modulemodules/mod_proxy_ftp.so

LoadModulenegotiation_modulemodules/mod_negotiation.so

#LoadModulerewrite_modulemodules/mod_rewrite.so

LoadModulesetenvif_modulemodules/mod_setenvif.so

#LoadModulespeling_modulemodules/mod_speling.so

#LoadModulestatus_modulemodules/mod_status.so

#LoadModuleunique_id_modulemodules/mod_unique_id.so

LoadModuleuserdir_modulemodules/mod_userdir.so

#LoadModuleusertrack_modulemodules/mod_usertrack.so

#LoadModulevhost_alias_modulemodules/mod_vhost_alias.so

LoadModulephp5_module"c:/wamp/php/php5apache2.dll"

LoadModuleperl_modulemodules/mod_perl.so



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Appendix D. Power and Speed: CGI and mod_perl

Tải bản đầy đủ ngay(0 tr)

×