Futurephpecho
phpecho 时间:2021-05-20 阅读:(
)
PHPTipsandTricksLCA2004Jan.
14,2004.
AdelaideRasmusLerdorfhttp://lerdorf.
com/lca04.
pdfSlide1/62January132004ManyThingsPHPisManyThingstoManyPeopleoTheBASICoftheWeboWebTemplateSystemoGeneral-purposeScriptingLanguageoAdvancedApplicationFrameworkoApplicationServer-2-Slide2/62January132004TemplateSystemoAmechanismtoseparatelogicfromlayout.
oThedefiningcharacteristiciswhereandhowtheintersectionbetweenlogicandlayoutisdone.
oPHPisageneral-purposetemplatingsystem.
oAnygeneral-purposetemplatingsystemwilleventuallybecomePHP.
-3-Slide3/62January132004PHPisBig!
January2004NetcraftReporto46,067,743Domainsqueriedo14,699,098Domains.
1,330,821IPaddressesoPHPinstalledon32%ofalldomainsSource:NetcraftJanuary2004ApacheModuleReporto9,286,904ApacheServerssurveyedo5,010,035(53.
95%)PHPo2,608,258(28.
09%)OpenSSLo2,527,385(27.
21%)mod_sslo1,845,621(19.
87%)Frontpageo1,597,830(17.
21%)mod_perlo411,443(4.
43%)DAVo380,012(4.
09%)mod_throttleo360,440(3.
88%)mod_log_byteso355,235(3.
83%)mod_bwlimitedo327,263(3.
52%)mod_jko233,404(2.
51%)mod_fastcgio222,410(2.
39%)AuthMySQLSource:SecuritySpace.
com-4-Slide4/62January132004KillerApps!
ThousandsofcoolPHPappsoutthere.
Somebetterthanothers.
HerearesomeIuse:oGallery-http://gallery.
menalto.
com/oSquirrelMail-http://squirrelmail.
orgoFudForum-http://fud.
prohost.
org/oSerendipity-http://s9y.
org/oCacti-http://www.
raxnet.
net/products/cacti/-5-Slide5/62January132004Server-SidePHPisaServer-sidelanguageEventhoughitisembeddedinHTMLfilesmuchliketheclient-sideJavascriptlanguage,PHPisserver-sideandallPHPtagswillbereplacedbytheserverbeforeanythingissenttothewebbrowser.
SoiftheHTMLfilecontains:Whattheenduserwouldseewitha"viewsource"inthebrowserwouldbe:HelloWorld-6-Slide6/62January132004EmbeddingPHPThe4availabletagstylesecho'ReallyLongTags-rarelyused';Output:ShortTags-MostcommonLongTags-PortableASPTagsReallyLongTags-rarelyused-7-Slide7/62January132004gdchartgdchartisafastgraphingextensionwrittenentirelyinC.
Itcanhandlemostcommontypesofgraphswiththeonlymajormissingfeaturebeingthatitcurrentlydoesn'thandlelegends.
Eithercreateyourownlegendbesideyourgraph,ormaybeevenlayeritintothebackgroundimageofyourgdchartgraphifyouhaveastaticlegend.
LineChartadd(array(2.
5,5.
1,8.
6,12.
0,15,9,8,7));$chart->add(array(5.
0,8.
0,9.
2,10.
2,7,8,10,9));$chart->add(array(8.
0,10.
0,14.
0,18.
2,16,14,12,10));$chart->labels=array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug");$chart->colors=array(0x1133aa,0xaa3311,0x33aa11);$chart->out(640,480,IMG_PNG);>Output:LineChartwithcustomaxesadd(array(2.
5,5.
1,8.
6,12.
0,15,9,8,7));$chart->add(array(5.
0,8.
0,9.
2,10.
2,7,8,10,9));$chart->add(array(8.
0,10.
0,14.
0,18.
2,16,14,12,10));$chart->labels=array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug");$chart->requested_ymin=0;$chart->ylabel_density=25;$chart->ylabel_fmt="%.
0f";$chart->colors=array(0x001133aa,0x00aa3311,0x33aa11);$chart->out(640,480,IMG_PNG);>Output:-8-3DAreaChartdepth=5;$chart->xtitle="Fruits";$chart->xtitle_color=0xffff00;$chart->bg_color=0x112233;$chart->xlabel_color=0xffffff;$chart->ylabel_color=0xffffff;$chart->colors=array(0x30ffff00,0x30ff00ff,0x3000ffff);$chart->add(array(2.
5,5.
1,8.
6,12.
0));$chart->add(array(5.
0,8.
0,9.
2,10.
2));$chart->add(array(8.
0,10.
0,14.
0,18.
2));$chart->labels=array("Apples","Oranges","Melons","Pears");$chart->out(640,480,IMG_PNG);>Output:-9-PieCharttitle="ThisisaSamplePieChart";$chart->title_font="/usr/share/fonts/truetype/CANDY.
ttf";$chart->title_ptsize=24;$chart->label_font="/usr/share/fonts/truetype/Jester.
ttf";$chart->label_ptsize=16;$chart->edge_color=0x000000;$chart->labels=array("red","green\r\n(exploded)","ltblue","purple","missing","cyan","blue");$chart->add(array(12.
5,20.
1,2.
0,22.
0,5.
0,18.
0,13.
0));$chart->missing=array(FALSE,FALSE,FALSE,FALSE,TRUE,FALSE,FALSE);$chart->explode=array(0,40,0,0,0,0,0);$chart->pie_depth=30;$chart->perspective=0;$chart->pie_angle=90;$chart->label_line=false;$chart->percent_labels=LABEL_ABOVE;$chart->out(640,480,IMG_PNG);>Output:-10-ComboHigh-Low-CloseCharttitle="High-Low-CloseOntopofanArea(volume)Graph";$chart->depth=5.
0;$chart->angle=50;$chart->annotation_font_size=FONT_TINY;$chart->anno_note="Earnings\nReport";$chart->anno_point=8;$chart->vol_color=0x40806040;$chart->grid=TICK_LABELS;$chart->ylabel_density=40;$chart->hlc_style=HLC_CONNECTING|HLC_I_CAP|HLC_DIAMOND;$chart->add_scatter(17.
0,3,SCATTER_TRIANGLE_UP,0x50808060,30);$chart->add(array(17.
8,17.
1,17.
3,17.
2,17.
1,17.
3,17.
3,17.
3,17.
1,17.
5,17.
4));$chart->add(array(16.
4,16.
0,15.
7,15.
25,16.
0,16.
1,16.
8,16.
5,16.
8,16.
2,16.
0));$chart->add(array(17.
0,16.
8,16.
9,15.
9,16.
8,17.
2,16.
8,17.
0,16.
9,16.
4,16.
1));$chart->add_combo(array(150.
0,100.
0,340.
0,999.
0,390.
0,420.
0,150.
0,100.
0,340.
0,1590.
0,700.
0));$chart->labels=array("May","Jun","Jul","Aug","Sep","Oct","Nov","Dec","Jan","Feb","Mar","Apr");$chart->out(640,480,IMG_PNG);>Output:-11--12-Slide8/62January132004PDFson-the-flyAPDFInvoice'595x842','letter'=>'612x792','legal'=>'612x1008');if(!
isset($type))$type='letter';list($x,$y)=explode('x',$sizes[$type]);$items=array(array('Ourspeciallow-costwidgetthatdoeseverything','299.
99'),array('Ourspecialhigh-costwidgetthatdoesmore','1899'),array('Abluewidget','29.
95'),array('Andaredwidget','49.
95'),array('Ayellowwidgetthatmakesnoise','49.
9'),array('Andonethatdoesn\'t','999.
95'),);pdf_begin_page($pdf,$x,$y);$im=pdf_open_jpeg($pdf,"php-big.
jpg");pdf_place_image($pdf,$im,5,$y-72,0.
5);pdf_close_image($pdf,$im);pdf_set_value($pdf,'textrendering',0);//fillpdf_set_font($pdf,"Helvetica",12,winansi);pdf_show_xy($pdf,'GenericEvilCompanyInc.
',145,$y-20);pdf_continue_text($pdf,'123MainStreet');pdf_continue_text($pdf,'DarkCity,CA98765');pdf_set_font($pdf,"Helvetica",10,winansi);pdf_show_xy($pdf,'HelplessCustomerLtd.
',20,$y-100);pdf_continue_text($pdf,'2SmallStreet');pdf_continue_text($pdf,'LittleTown,ID56789');pdf_set_font($pdf,"Helvetica",10,winansi);pdf_show_xy($pdf,'Terms:Net30',150,$y-100);pdf_continue_text($pdf,'PO#:12345');pdf_set_font($pdf,"Helvetica-Bold",30,winansi);pdf_show_xy($pdf,"INVOICE",$x-250,$y-112);pdf_setcolor($pdf,'fill','gray',0.
9,0,0,0);pdf_rect($pdf,20,80,$x-40,$y-212);pdf_fill_stroke($pdf);$offset=184;$i=0;while($y-$offset>80){pdf_setcolor($pdf,'fill','gray',($i%2)0.
8:1,0,0,0);pdf_setcolor($pdf,'stroke','gray',($i%2)0.
8:1,0,0,0);pdf_rect($pdf,21,$y-$offset,$x-42,24);pdf_fill_stroke($pdf);$i++;$offset+=24;}pdf_setcolor($pdf,'fill','gray',0,0,0,0);pdf_setcolor($pdf,'stroke','gray',0,0,0,0);pdf_moveto($pdf,20,$y-160);pdf_lineto($pdf,$x-20,$y-160);pdf_stroke($pdf);pdf_moveto($pdf,$x-140,$y-160);pdf_lineto($pdf,$x-140,80);-13-pdf_stroke($pdf);pdf_set_font($pdf,"Times-Bold",18,winansi);pdf_show_xy($pdf,"Item",30,$y-150);pdf_show_xy($pdf,"Price",$x-100,$y-150);pdf_set_font($pdf,"Times-Italic",15,winansi);$offset=177;foreach($itemsas$item){pdf_show_xy($pdf,$item[0],30,$y-$offset);pdf_show_boxed($pdf,'$'.
number_format($item[1],2),$x-55,$y-$offset,0,0,'right');$offset+=24;$total+=$item[1];}pdf_set_font($pdf,"Times-Bold",17,winansi);$offset+=24;pdf_show_xy($pdf,'Total',30,$y-$offset);pdf_show_boxed($pdf,'$'.
number_format($total,2),$x-55,$y-$offset,0,0,'right');pdf_end_page($pdf);pdf_close($pdf);$data=pdf_get_buffer($pdf);header('Content-type:application/pdf');header("Content-disposition:inline;filename=invoice.
pdf");header("Content-length:".
strlen($data));echo$data;>-14-Slide9/62January132004Ming-FlashSeehttp://www.
opaque.
net/ming/getWidth();$h=$jpg->getHeight();$f=$s->addFill($jpg);$f->moveTo(-$w/2,-$h/2);$s->setRightFill($f);$s->movePenTo(-$w/2,-$h/2);$s->drawLine($w,0);$s->drawLine(0,$h);$s->drawLine(-$w,0);$s->drawLine(0,-$h);$p=newSWFSprite();$i=$p->add($s);for($step=0;$stepnextFrame();$i->rotate(-2);}$m=newSWFMovie();$i=$m->add($p);$i->moveTo(230,120);$m->setRate(100);$m->setDimension($w1.
8,$h1.
8);header('Content-type:application/x-shockwave-flash');$m->output();>Output:FWS%xeHd*CC$.
'",#(7),01444'9=828KP÷]|Q#{&Qol|^C'N{kHx'>KC-'ViUtAM+LIe—)ie*N}l+_áRYNóy…f÷P*–q{6ü)Sè.
óqZxèT0a=';~Qs46w6"'-t}zXàüSm‰sA·êím°hRug*>NSK,t'H)]s0)@R")@W(-sr*b")5c±iJe=\*Z\Oh5JT°3qlq±XCZBMGg&uC-15-Slide10/62January132004PEARExamplesprompt:~>pearlistInstalledpackages:|Package|Version|State||Archive_Tar|0.
9|stable||Console_Getopt|0.
11|beta||DB|1.
2|stable||Mail|1.
0|stable||Net_Sieve|0.
8|stable||Net_Socket|1.
0.
1|stable||PEAR|0.
91-dev|beta||XML_Parser|1.
0|stable||XML_RPC|1.
0.
3|stable||XML_RSS|0.
9.
1|stable||XML_Tree|1.
1|stable|prompt:~>pearremote-listAvailablepackages:|Package|Version||Archive_Tar|0.
9||Auth|1.
0.
2||Auth_HTTP|1.
0.
1||Benchmark|1.
1||Cache|1.
5.
1||Config|0.
3.
1||Crypt_CBC|0.
3||Crypt_Rc4|0.
1||Date|1.
1||DB|1.
3||DB_ado|1.
1||DB_Pager|0.
7||File|1.
0.
2||File_Find|0.
1||File_SearchReplace|1.
0||HTML_Common|1.
0||HTML_QuickForm|2.
3||HTML_Table|1.
1||HTML_TreeMenu|1.
0.
3||HTTP|1.
1||HTTP_Request|1.
0||HTTP_Upload|0.
8||Log|1.
2||Mail|1.
0||Mail_Mime|1.
2||Net_CheckIP|1.
0.
1||Net_Curl|0.
1||Net_Dig|0.
1||Net_Geo|1.
0||Net_NNTP|0.
1||Net_Ping|1.
0.
1||Net_POP3|1.
1||Net_Portscan|1.
0.
1||Net_Sieve|0.
8||Net_SMTP|1.
0||Net_Socket|1.
0.
1||Net_URL|1.
0.
3||Net_UserAgent_Detect|1.
0||Numbers_Roman|0.
1||Pager|1.
0.
4||Payment_Clieop|0.
1||PEAR|0.
9||PHPUnit|0.
3||Science_Chemistry|1.
0.
2||System_Command|1.
0||XML_CSSML|1.
1||XML_fo2pdf|0.
97||XML_image2svg|0.
1|-16-|XML_Parser|1.
0||XML_RPC|1.
0.
3||XML_RSS|0.
9.
1||XML_Transformer|0.
3||XML_Tree|1.
1|prompt:~>pearlist-upgradesAvailableUpgrades(stable):|Package|Version|Size||DB|1.
3|58kB|prompt:~>pearupgradeDBdownloadingDB-1.
3.
tgz.
.
.
.
.
.
done:59,332bytesupgradeok:DB1.
3prompt:~>pearinstallPHPUnitdownloadingPHPUnit-0.
3.
tgz.
.
.
.
.
.
done:7,284bytesinstallok:PHPUnit0.
3-17-Slide11/62January132004PECLoPHPExtensionCodeLibraryoSharedextensionsoMakesuseofthe'pear'tooloFuturehomeforallextensions[derick@kossunl]$sudopear-vinstallhttp://files.
derickrethans.
nl/xdebug-1.
2.
0.
tgzdownloadingxdebug-1.
2.
0.
tgz.
.
.
.
.
.
done:58,608bytes28sourcefiles,buildingrunning:phpizePHPApiVersion:20020918ZendModuleApiNo:20020429ZendExtensionApiNo:20021010buildingin/var/tmp/pear-build-root/xdebug-1.
2.
0running:/tmp/tmpXOqy3A/xdebug-1.
2.
0/configurerunning:makexdebug.
socopiedto/tmp/tmpXOqy3A/xdebug-1.
2.
0/xdebug.
soinstallok:xdebug1.
2.
0-18-Slide12/62January132004SetupCheckyourPHPSetupforMySQLsupportIfnotenabledSomepossiblewaystoenableMySQLsupport:apt-getinstallphp-mysqlrpm-Uvhphp-mysql-4.
2.
2-1.
i386.
rpm.
/configure--with-mysql=shared,/usrcpmodules/mysql.
so/usr/local/lib/phpextension_dir=/usr/local/lib/phpextension=mysql.
so-19-Slide13/62January132004SanityCheckMakesureMySQLisrunningprompt:~>mysqlshow|Databases||mysql||test|OrwiththelatestPHPOutput:Uptime:1169Threads:1Questions:86Slowqueries:15Opens:16Flushtables:1Opentables:1Queriespersecondavg:0.
074-20-Slide14/62January132004ConnectingtoMySQLThesimpleconnectionOutput:Resourceid#91Othervariations-21-Slide15/62January132004PersistentConnectionsThesimpleconnectionOutput:Resourceid#94CaveatsoWatchoutformulti-credentialconnectionsoMakesureyoumatchupmax_connectionsandMaxClients-22-Slide16/62January132004CreatingaDatabaseCreateaDBOutput:DatabasefoocreatedCreateaTableOutput:Tablecreated-23-Slide17/62January132004InsertingDataINSERTQuery";}else{echomysql_error().
"";}}mysql_connect('localhost');mysql_select_db('foo');add_user('rasmus','foobar','RasmusLerdorf','rasmus@php.
net');add_user('carl','carlspass','CarlAlexandeRLerdorf','carl@lerdorf.
com');>Output:RowinsertedRowinserted-24-Slide18/62January132004SelectingDataSELECTQuery\n";}}>Output:rasmus-EGRsIW/RRmGbU-RasmusLerdorf-rasmus@php.
net-20040113154208carl-EGMHoZe7RYfNY-CarlAlexandeRLerdorf-carl@lerdorf.
com-20040113154208mysql_fetch_array()\n";}}>Output:carl-EGMHoZe7RYfNY-CarlAlexandeRLerdorf-carl@lerdorf.
com-20040113154208rasmus-EGRsIW/RRmGbU-RasmusLerdorf-rasmus@php.
net-20040113154208-25-Slide19/62January132004DealingwithtimestampsUsingDATE_FORMAT\n";}}else{echomysql_error();}>Output:rasmus-rasmus@php.
net-TuesdayJanuary13th,200403:42:08PMcarl-carl@lerdorf.
com-TuesdayJanuary13th,200403:42:08PM-26-Slide20/62January132004ChangingExistingRowsUsingUPDATEOutput:1REPLACEINTOYoucanalsouseREPLACEINTOtoupdatearowifitexistsandinsertitifitdoesn't.
-27-Slide21/62January132004MagicQuotesEscapingtroublesomecharactersWhenyouareinsertingdataintoaMySQLdatabase,certaincharactershaveaspecialmeaningandmustthereforebeescapedifyouwishtoinsertthesecharactersliterally.
Bydefault,PHPwillescapethesecharactersforyouinanydatacomingfromtheuserinGET,PostorCookiedata.
ThismagicescapingisknownasMagicQuotesandcanbeconfiguredinyourphp.
inifilebysettingthemagic_quotes_gpcdirective.
Thecharactersaffectedare\'"andNUL(char0).
Ifthesecharactersappearinuser-supplieddatatheywillbeescapedwitha\(backslash).
Somepeopleprefertoturnthisfeatureoffandhandleescapingdatamanuallyusingtheaddslashes()function.
Thereisaconversefunction,stripslashes(),whichremovesthebackslashcharactersinanescapedstring.
-28-Slide22/62January132004SquidForreallybusysites,areverseproxylikeSquidismagical!
Eitherrunitasasingle-serveraccelerator:Orasafront-endcachetoanumberoflocalorremoteservers:Note:Watchoutforanyuseof$REMOTE_ADDRinyourPHPscripts.
Use$HTTP_X_FORWARDED_FORinstead.
-29-Slide23/62January132004SquidConfigurationMakeitlistentoport80onourexternalinterface:http_port198.
186.
203.
51:80Ifwedon'tdocgi-binstuff,commenttheseout:#aclQUERYurlpath_regexcgi-bin#no_cachedenyQUERYIfwehaveplentyofRAM,bumpthisupabit:cache_mem16MBmaximum_object_size14096KBSpecifywheretostorecachedfiles(sizeinMegs,level1subdirs,level2subdirs)cache_dirufs/local/squid/cache50016256Getridofthebigstore.
logfile:cache_store_lognoneSetourSNMPpubliccommunitystring:aclsnmppublicsnmp_communitypublicGetridof"allowall"anduselistofhostsweareblocking(1ipperline):#http_accessallowallaclforbiddensrc"/local/squid/etc/forbidden"http_accessallow!
forbiddenSetuser/groupsquidshouldrunas:cache_effective_usersquidcache_effective_groupdaemonSingle-serverreverseproxysetup(setupApachetolistentoport80ontheloopback):httpd_accel_host127.
0.
0.
1httpd_accel_port80httpd_accel_single_hostonhttpd_accel_uses_host_headeronOnlyallowlocalhostaccessthroughsnmp:snmp_accessallowsnmppubliclocalhost-30-Slide24/62January132004MySQLReplicationAsofversion3.
23.
15(trytouse3.
23.
29orlater),MySQLsupportsone-wayreplication.
Sincemostwebapplicationsusuallyhavemorereadsthanwrites,anarchitecturewhichdistributesreadsacrossmultipleserverscanbeverybeneficial.
IntypicalMySQLfashion,settingupreplicationistrivial.
Onyourmasterserveraddthistoyour"my.
cnf"file:[mysqld]log-binserver-id=1Andaddareplicationuseridforslavestologinas:GRANTFILEON.
TOrepl@"%"IDENTIFIEDBY'foobar';IfyouareusingMySQL4.
0.
2orlater,replaceFILEwithREPLICATIONSLAVEintheabove.
Thenonyourslaveservers:[mysqld]set-variable=max_connections=200log-binmaster-host=192.
168.
0.
1master-user=replmaster-password=foobarmaster-port=3306server-id=2Makesureeachslavehasitsownuniqueserver-id.
Andsincethesewillberead-onlyslaves,youcanstartthemwiththeseoptionstospeedthemupabit:--skip-bdb--low-priority-updates--delay-key-write-for-all-tablesStopyourmasterserver.
Copythetablefilestoeachofyourslaveservers.
Restartthemaster,thenstartalltheslaves.
Andyouaredone.
CombiningMySQLreplicationwithaSquidreversecacheandredirectorandyoumighthaveanarchitecturelikethis:-31-Youwouldthenwriteyourapplicationtosendalldatabasewritestothemasterserverandallreadstothelocalslave.
Itisalsopossibletosetuptwo-wayreplication,butyouwouldneedtosupplyyourownapplication-levellogictomaintainatomicityofdistributedwrites.
Andyoulosealotoftheadvantagesofthisarchitectureifyoudothisasthewriteswouldhavetogotoalltheslavesanyway.
-32-Slide25/62January132004$PATH_INFO$PATH_INFOisyourfriendwhenitcomestocreatingcleanURLS.
TakeforexamplethisURL:http://www.
company.
com/products/routersIftheApacheconfigurationcontainsthisblock:ForceTypeapplication/x-httpd-phpThenallyouhavetodoiscreateaPHPscriptinyourDOCUMENT_ROOTnamed'products'andyoucanusethe$PATH_INFOvariablewhichwillcontainthestring,'/routers',tomakeaDBquery.
-33-Slide26/62January132004ErrorDocumentApache'sErrorDocumentdirectivecancomeinhandy.
Forexample,thislineinyourApacheconfigurationfile:ErrorDocument404/error.
phpCanbeusedtoredirectall404errorstoaPHPscript.
Thefollowingservervariablesareofinterest:o$REDIRECT_ERROR_NOTES-Filedoesnotexist:/docroot/boguso$REDIRECT_REQUEST_METHOD-GETo$REDIRECT_STATUS-404o$REDIRECT_URL-/docroot/bogusDon'tforgettosenda404statusifyouchoosenottoredirecttoarealpage.
InterestingusesoSearchforclosestmatchingvalidURLandredirectoUseattemptedurltextasaDBkeywordlookupoFunkycaching-34-Slide27/62January132004Cool!
Super-coolDynamicImageGeneratorWanttobecoolerthanallyourfriendsWellhereitis!
First,setupanErrorDocument404handlerforyourimagesdirectory.
ErrorDocument404/images/generate.
php')Thengenerate.
phplookslikethis:TheURL,http://localhost/images/button_test_000000.
pngproducesthisimage:-35-Slide28/62January132004FunkyCachingAninterestingwaytohandlecachingistohaveall404'sredirectedtoaPHPscript.
ErrorDocument404/generate.
phpTheninyourgenerate.
phpscriptusethecontentsof$REDIRECT_URItodeterminewhichURLthepersonwastryingtogetto.
InyourdatabaseyouwouldthenhavefieldslinkingcontenttotheURLtheyaffectandfromthatyoushouldbeabletogeneratethepage.
Theninyourgenerate.
phpscriptdosomethinglike:So,thewayitworks,whenarequestcomesinforapagethatdoesn'texist,generate.
phpchecksthedatabaseanddeterminesifitshouldactuallyexistandifsoitwillcreateitandrespondwiththisgenerateddata.
ThenextrequestforthatsameURLwillgetthegeneratedpagedirectly.
Soinordertorefreshyourcacheyousimplyhavetodeletethefiles.
-36-Slide29/62January132004AppArchitectureAsuggestedarchitectureforaPHPapplication.
Thetemplatelayershouldhaveaslittlebusinesslogicaspossible.
Asyougodownyouhavelesspresentationandmorebusinesslogic.
-37-Slide30/62January132004SimplisticExampleIntermsofareal-worldexampleofwhatgoesinthese4differentlayers,assumewearewritingadatabase-backedapplicationthatneedstofetchauserrecordcontainingvariousfields.
Thisisaverycommonthingtodoinawebapp.
Ourtemplatelayermightlooksomethinglikethis:php.
iniauto_prepend_file=".
/helpers.
inc"include_path="/usr/local/lib/php"TemplateLayerHeading1PagecontentHeading2YadaYadaHeading3PagecontentTemplateHelpers';>\n";if($age=birthday($user)){echo"Congratulations,todayisyour";echo"$agebirthday!
\n";}}functiontitle($title){echo"$title\n";echo"\n";}functionfooter(){echo"\n";}>BusinessLogic10&&($age100)InthiscasethefinallayerwritteninCcontainsthemysql_*functions,andthedate()function.
ThesehappentobestandardPHPfunctions.
Ifbirthday()iscalledmanytimesoneverysinglerequestandsincehowyoufigureoutifitissomeone'sbirthdayisunlikelytochangeveryoften,thismaybeagoodcandidatetotranslateintoC.
Although,inthisexample,thebirthdayfunctionisprobablytoosimpletoseemuchofaperformanceimprovement.
Ontheotherhand,otherthanalittlebitofaddedparameterparsing,ifyoucomparetheCversionofbirthday()tothePHPversion,itisn'tthatmuchhardertowriteitinC.
CLayerPHP_FUNCTION(birthday){time_ttimestamp,now;structtmta1,tmbuf1,ta2,tmbuf2;intage;charret_age[8];if(zend_parse_parameters(1TSRMLS_CC,"l",×tamp)==FAILURE)return;ta1=php_localtime_r(×tamp,&tmbuf1);time(&now);ta2=php_localtime_r(&now,&tmbuf2);if(tmbuf1.
tm_mday==tmbuf2.
tm_mday&&tmbuf1.
tm_mon==tmbuf2.
tm_mon){age=tmbuf2.
tm_year-tmbuf1.
tm_year;if((age100)>10&&(age100)resultsinthiserrorwhensafemodeisenabled:Warning:SAFEMODERestrictionineffect.
Thescriptwhoseuidis500isnotallowedtoaccess/etc/passwdownedbyuid0in/docroot/script.
phponline2Ifinsteadofsafe_mode,yousetanopen_basedirdirectorythenallfileoperationswillbelimitedtofilesunderthespecifieddirectory.
Forexample(Apachehttpd.
confexample):php_admin_valueopen_basedir/docrootIfyourunthesamescript.
phpwiththisopen_basedirsettingthenthisistheresult:Warning:open_basedirrestrictionineffect.
Fileisinwrongdirectoryin/docroot/script.
phponline2Youcanalsodisableindividualfunctions.
Ifweaddthistoourphp.
inifile:disable_functionsreadfile,systemThenwegetthisoutput:Warning:readfile()hasbeendisabledforsecurityreasonsin/docroot/script.
phponline2-40-Slide32/62January132004SecurityWatchforuninitializedvariablesCatchthesebysettingtheerror_reportingleveltoE_ALL.
Theabovescriptwouldgeneratethiswarning(assuming$userisset):Warning:Undefinedvariable:okinscript.
phponline6Youcanofcoursealsoturnoffregister_globals,butthataddressesthesymptomratherthantheproblem.
-41-Slide33/62January132004SecurityNevertrustuserdata!
Turningoffregister_globalsdoesn'tmakethisanymoresecure.
Thescriptwouldinsteadlooklikethis:Theonlywaytosecuresomethinglikethisistobereallyparanoidaboutcleaninguserinput.
InthiscaseifyoureallywanttheusertobeabletospecifyafilenamethatgetsusedinanyofPHP'sfilefunctions,dosomethinglikethis:Youmayalsowanttostripoutanypathandonlytakethefilenamecomponent.
Aneasywaytodothatistousethebasename()function.
Orperhapschecktheextensionofthefile.
Youcangettheextensionusingthiscode:-42-Slide34/62January132004SecurityAgain,nevertrustuserdata!
Inthisexampleyouwanttomakesurethattheusercan'tpassin$dirsettosomethinglike:".
;cat/etc/passwd"Theremedyistouseescapeshellarg()whichplacestheargumentinsidesinglequotesandescapesanysinglequotecharactersinthestring.
Beyondmakingsureuserscan'tpassinargumentsthatexecutesothersystemcalls,makesurethattheargumentitselfisokandonlyaccessesdatayouwanttheuserstohaveaccessto.
-43-Slide35/62January132004SecurityManyusersplacecodeinmultiplefilesandincludethesefiles:OrperhapsBothofthesecanbeproblematiciftheincludedfileisaccessiblesomewhereundertheDOCUMENT_ROOTdirectory.
ThebestsolutionistoplacethesefilesoutsideoftheDOCUMENT_ROOTdirectorywheretheyarenotaccessibledirectly.
Youcanaddthisexternaldirectorytoyourinclude_pathconfigurationsetting.
AnotheroptionistorejectanydirectrequestsforthesefilesinyourApacheconfiguration.
Youcanusearulelikethisinyour"httpd.
conf"file:Orderallow,denyDenyfromall-44-Slide36/62January132004SecurityTakethisstandardfileuploadform:Sendthisfile:Thecorrectwaytoputtheuploadedfileintherightplace:IfyouareuploadingfilestobeplacedsomewhereundertheDOCUMENT_ROOTthenyouneedtobeveryparanoidincheckingwhatyouareputtingthere.
Forexample,youwouldn'twanttoletpeopleuploadarbitraryPHPscriptsthattheycanthenbrowsetoinordertoexecutethem.
Herewegetparanoidaboutcheckingthatonlyimagefilescanbeuploaded.
Weevenlookatthecontentsofthefileandensurethatthefileextensionmatchesthecontent.
-45-Slide37/62January132004PHP5OO-ReferencesInPHP4name=$name;}}functionchangeName(&$obj,$name){$obj->name=$name;}$linux=newOS('linux');$win=$linux;changeName($win,'windows');echo$linux->name.
"\n";echo$win->name;>Output:linuxwindowsInPHP5name=$name;}}functionchangeName($obj,$name){$obj->name=$name;}$linux=newOS('linux');$win=$linux->__clone();changeName($win,'windows');echo$linux->name.
"\n";echo$win->name;>-46-Slide38/62January132004PHP5OO-*structorsConstructorsandDestructors-47-Slide39/62January132004PHP5OO-Privateo'Strongest'accessleveloCanonlybeaccessed/calledfromthesameclassoForceuseofget()/set()functionstoaccesspropertiesaction='fun';}}$br=newBedroom();echo$br->action.
"\n";>Fatalerror:Cannotaccessprivatepropertybedroom::$actioninfoo.
phponline12-48-Slide40/62January132004PHP5OO-ProtectedOnlyaccessable/callablebythesame,oraninheritedclass.
action='fun';}protectedfunctionpeek(){echo$this->action.
"\n";}}classKeyholeextendsBedroom{functionpeek(){echo$this->action.
"\n";}}$kh=newKeyhole();$kh->peek();$br=newBedroom();$br->peek();/Doesn'twork/>-49-Slide41/62January132004PHP5OO-set/getPropertyaccesshandlerscombinedwith'private'canbeusedasareplacementfordynamicproperties.
names[$name]=$value;}publicfunctiongetNames(){return$this->names;}}$osses=newOSses();$osses->linux='rocks';$osses->windows='blows';var_dump($osses->getNames());>array(1){["linux"]=>string(5)"rocks"}-50-Slide42/62January132004PHP5OO-call__call()isusedtocatchmethodcallsthesameway__get()and__set()isusedtocatchpropertyaccessesrusty();$h->anton();>HelloRusty!
HelloAnton!
-51-Slide43/62January132004PHP5OO-ExceptionsPHP4:";print_r(stream_get_wrappers());print_r(stream_get_filters());echo"";>Array([0]=>php[1]=>file[2]=>http[3]=>ftp[4]=>compress.
zlib)Array([0]=>string.
rot13[1]=>string.
toupper[2]=>string.
tolower[3]=>string.
strip_tags[4]=>convert.
*)Examplesstream_copy_to_stream-53-Slide45/62January132004PHP-AWK-BRunPHPbeforeprocessinginputlines-RRunPHPforeveryinputline-FParseandexecuteforeveryinputline-ERunPHPafterprocessingallinputlines$find.
|\php-B'$l=0;'\-R'$l+=count(file($argn));'\-E'echo"Lines:$l\n";'Lines:102643-54-Slide46/62January132004DOMXMLloadchild_nodes();$root=$root[0];$books=$root->child_nodes();foreach($booksas$book){if(@$book->tagname=='book'){$content=$book->child_nodes();foreach($contentas$elem){if(@$elem->tagname=='author'){$author=$elem->get_content();}if(@$elem->tagname=='title'){$title=$elem->get_content();}}echo"{$title}waswrittenby{$author}\n";}}>-55-Slide47/62January132004SimpleXMLNomoreSAXparsingandwegetDTDvalidationandXPathqueriesBookXMLFileTheGrapesofWrathJohnSteinbeckThePearlJohnSteinbeckBookPHPFilebookas$book){echo"{$book->title}waswrittenby{$book->author}\n";}>-56-Slide48/62January132004SimpleRDFWorld'sEasiestRDFparserchannel->title;foreach($rdf->channel->itemas$item){echo'link.
'">'.
$item->title.
'';}>-57-Slide49/62January132004SQLiteSQLInterfaceforflatfiles!
ExampleOutput:array0=>'fnord''bar'=>'fnord'-58-Slide50/62January132004SQLiteSamethingwiththeOOinterfaceExamplequery("CREATETABLEfoo(c1date,c2time,c3varchar(64))");$db->query("INSERTINTOfooVALUES('2002-01-02','12:49:00',NULL)");$r=$db->query("SELECT*fromfoo");$result=$r->fetch_array();>-59-Slide51/62January132004PHPOpcodeCachesStandardPHP-60-Slide52/62January132004PHPOpcodeCachesPHPwithanOpcodeCache-61-Slide53/62January132004PHPOpcodeCachesThereareanumberofthemoutthere.
oAPC-opensourceoIonCubeAccelerator-free,butclosedsourceoZendCache-commercialInstallationTypicallyverytrivial.
ForIonCube:yinstinstallyapache_libphp_phpaAllitdoesisstickaphpa.
sosomewhereandthentellsPHPaboutitwiththisina.
inifile:zend_extension="/path/to/phpa.
so"-62-Slide54/62January132004WhenToOptimizePrematureOptimizationIsTheRootofAllEvil.
-DonaldE.
Knuth-63-Slide55/62January132004TuningSomesimpleguidelinesoTrytolimityourselfto5orlessincludesperrequestoDon'tgooverboardonOOP.
Usewhereappropriate.
oSamegoesforLayers.
Abstraction,Indirection,abstractclasses.
oEverythinghasacostoUseanopcodecacheoWatchyourregularexpressions!
oCache!
Cache!
Cache!
oIfyouhaveplentyofCPUbutlimitedbandwidth,turnonoutputcompression-64-Slide56/62January132004BenchmarkingLet'shavealookathowwemightbenchmarkandsubsequentlytuneaPHPserver.
Wewillusetwomachines.
AclientmachinetorunourHTTPloadprogram(http_loadfromacme.
com)andaP41.
7Gserverwith256MofRAM.
Wewillalsobeusing3freelyavailableopcodecaches:http://cvs.
php.
net/cvs.
php/pear/PECL/apchttp://www.
turckware.
ru/en/e_mmc.
htmhttp://www.
ioncube.
comDon'tblowyouriobuffers!
#TochangethisonLinux,catalargernumber#into/proc/sys/net/core/wmem_maxinyour#httpdstartupscriptSendBufferSize65535ThisisourbenchmarkscriptSimplePHPBenchmarkStringManipulationIncluding2filesfor-loopandcallingafunctionmanytimesDefineandInstantiateanobjectandcallsomemethods\n";}-65-functionset_var1($value){$this->test_var1=$value;echo"test_var1propertysetto$value\n";returntrue;}functionset_var2($value){$this->test_var2=$value;echo"test_var2propertysetto$value\n";returntrue;}functionset_var3($value){$this->test_var3=$value;echo"test_var3propertysetto$value\n";returntrue;}functionset_var4($value){$this->test_var4=$value;echo"test_var4propertysetto$value\n";returntrue;}functiondisp(){echo"";var_dump($this);echo"";}}$obj=newtest_class(1,'arg2');$obj->set_var1('test1');$obj->set_var2(123);$obj->set_var3($a);/Arrayfromprevioustest/$obj->set_var4(array(1,2,3,4,5,6,7,8,9));$obj->disp();>bench_include1.
inc$arg2)return$arg1;elseif($arg1bench_include2.
incThisisjustabunchofplaintextinanincludefile.
Thisisjustabunchofplaintextinanincludefile.
Thisisjustabunchofplaintextinanincludefile.
Thisisjustabunchofplaintextinanincludefile.
Thisisjustabunchofplaintextinanincludefile.
Thisisjustabunchofplaintextinanincludefile.
Thisisjustabunchofplaintextinanincludefile.
Thisisjustabunchofplaintextinanincludefile.
Thisisjustabunchofplaintextinanincludefile.
Thisisjustabunchofplaintextinanincludefile.
Thisisjustabunchofplaintextinanincludefile.
Thisisjustabunchofplaintextinanincludefile.
Thisisjustabunchofplaintextinanincludefile.
Thisisjustabunchofplaintextinanincludefile.
Thisisjustabunchofplaintextinanincludefile.
Thisisjustabunchofplaintextinanincludefile.
Thisisjustabunchofplaintextinanincludefile.
Thisisjustabunchofplaintextinanincludefile.
Thisisjustabunchofplaintextinanincludefile.
Thisisjustabunchofplaintextinanincludefile.
Thisisjustabunchofplaintextinanincludefile.
Thisisjustabunchofplaintextinanincludefile.
-66-Thisisjustabunchofplaintextinanincludefile.
-67-Slide57/62January132004BenchmarkingResultsAnhttp_loadrun2500fetches,5maxparallel,1.
962e+07bytes,in15.
9486seconds7848meanbytes/connection156.
753fetches/sec,1.
2302e+06bytes/secmsecs/connect:1.
40331mean,2999.
44max,0.
171minmsecs/first-response:29.
4603mean,648.
731max,6.
005minHTTPresponsecodes:code200--2500Wheneveryoudoanysortofloadtesting,youneedlookbeyondjusttherawnumbersandhavealookatwhatyourserverisactuallydoing.
Usevmstat:BasePHPLoadprocsmemorypagedisksfaultscpurbwavmfrefltrepipofrsrad0ac0insycsussyid25001494721757226000000016631239043918020050014947217532270000000166512322444477230700149472174922400000201657124094771742605001494721745228000000016871252048568218025001494721741228000000016491241347567822050014947217372230000000164512199441777230500149084173322700000101679125644385762405001494641730426000301016631233645517921050014946417264270000000166212480466382180LoadwithAPCcacheprocsmemorypagedisksfaultscpurbwavmfrefltrepipofrsrad0ac0insycsussyid500150140119362900000001629122034687752505001501401188828000000016191200745797921050015014011848280000000164012305425276240500150140118082500000101630120064628841602500150140117762700000001635123044118881205001501401173626000000016271205943818020050015052811696220000011016351217846858317050015052811656260000000162412027465184160LoadwithIonCubecacheprocsmemorypagedisksfaultscpurbwavmfrefltrepipofrsrad0ac0insycsussyid500127996145162800000001608193434382772305001279961447625000000016011941646288218080012761614436230000010160019181460476240260012761614400240001010160519439394084160500127616143602600000001612194164582792105001289561432825000001015991933645597228060012895614288260000000159819390444479210LoadwithTurckMMCacheprocsmemorypagedisksfaultscpurbwavmfrefltrepipofrsrad0ac0insycsussyid30013669613284290000000169414846474879210500136696132443300000101711148154472742605001363081320428000000016961482447718317150013668813164270000000169214590488083170-68-600136688131162600000101687147624010831705001356961300425000000016931475948407921070013569612956260000010167614477464374251OurbenchmarktestwasdeliberatelydesignedtohavequiteabitofPHPprocessingandnotawholelotofoutput.
7kissomewhatsmallforawebpage.
Ifinsteadwehaveawholelotofoutput,chancesarewewillbeio-boundinsteadofcpu-bound.
Ifyouareio-bound,thereislittlesenseinoptimizingatthePHPlevel.
Evidenceofanio-boundtestprocsmemorypagedisksfaultscpurbwavmfrefltrepipofrsrad0ac0insycsussyid400132860157241033000000044579543704225745001328601572410090000000443671435973247360013286015716980000000044469253603523722001328601571610280000060451472036962247330013247215716101800000204501946367322276400132472157161039000000045657373718226733001324721570810100000020449893836392247520013247215708101200000004543730366552570Thingstotryifyouareio-bound[php.
ini]output_handler=ob_gzhandler[httpd.
conf]LoadModulegzip_modulelib/apache/mod_gzip.
so-69-Slide58/62January132004BenchmarkingResultsSo,wehavedeterminedwearecpu-boundandweneedtogofaster.
WhatcanwedoSomelow-hangingfruit:include_pathinclude_path="/usr/share/pear:.
"open_basediropen_basedir="/usr/share/htdocs/:/usr/share/pear/"open_basedircheckingaddssomeextrasyscallstoeveryfileoperation.
Itcanbeuseful,butitisratherexpensive,soturnitoffifyoudon'tthinkyouneedit.
variables_ordervariables_order="GPC"Ifyouneverusecookies,turnthoseofftooAddanOpcodeCachezend_extension=/usr/local/lib/php/20020429/apc.
soapc.
enabled=1apc.
shm_segments=1apc.
optimization=0apc.
shm_size=30apc.
num_files_hint=10apc.
gc_ttl=10apc.
mmap_file_mask=/tmp/apc.
XXXXXXapc.
filters=Results156request/secStandardPHP4.
3161requests/secFixinclude_path,andonlypopulateGP191requests/secAddIonCubeAcceleratorontop196requests/secAPCnooptimizer,IPCsharedmem+semaphorelocking198requests/secTurckMMCachenooptimizerwithspinlocks200requests/secAPCnooptimizer,mmapmem+userspacesleeplocks202requests/secTurckMMCachewithoptimizerandspinlocks-70-Slide59/62January132004ProfilingPHPWhyProfileBecauseyourassumptionsofhowthingsworkbehindthescenesarenotalwayscorrect.
Byprofilingyourcodeyoucanidentifywherethebottlenecksarequantitatively.
HowPECLtotherescue!
www:~>pearinstallapddownloadingapd-0.
4p1.
tgz.
.
.
.
.
.
done:39,605bytes16sourcefiles,buildingrunning:phpizePHPApiVersion:20020918ZendModuleApiNo:20020429ZendExtensionApiNo:20021010buildingin/var/tmp/pear-build-root/apd-0.
4p1running:/tmp/tmprFlAqf/apd-0.
4p1/configurerunning:makeapd.
socopiedto/tmp/tmprFlAqf/apd-0.
4p1/apd.
soinstallok:apd0.
4p1Theninyourphp.
inifile:zend_extension="/usr/local/lib/php/apd.
so"apd.
dumpdir=/tmpItisn'tcompletelytransparent.
Youneedtotelltheprofilerwhentostartprofiling.
Atthetopofascriptyouwanttoprofile,addthiscall:Theusethecommand-linetoolcalledpprofp:wwww:~>pprofppprofpSortoptions-aSortbyalphabeticnamesofsubroutines.
-lSortbynumberofcallstosubroutines-mSortbymemoryusedinafunctioncall.
-rSortbyrealtimespentinsubroutines.
-RSortbyrealtimespentinsubroutines(inclusiveofchildcalls).
-sSortbysystemtimespentinsubroutines.
-SSortbysystemtimespentinsubroutines(inclusiveofchildcalls).
-uSortbyusertimespentinsubroutines.
-USortbyusertimespentinsubroutines(inclusiveofchildcalls).
-vSortbyaverageamountoftimespentinsubroutines.
-zSortbyuser+systemtimespentinsubroutines.
(default)Displayoptions-cDisplayRealtimeelapsedalongsidecalltree.
-iSuppressreportingforphpbuiltinfunctions-OSpecifiesmaximumnumberofsubroutinestodisplay.
(default15)-tDisplaycompressedcalltree.
-TDisplayuncompressedcalltree.
%pprofp-z/tmp/pprof.
48478Tracefor/home/y/share/htdocs/bench_main.
phpTotalElapsedTime=0.
01TotalSystemTime=0.
01-71-TotalUserTime=0.
01RealUserSystemsecs/cumm%Time(excl/cumm)(excl/cumm)(excl/cumm)Callscalls/callMemoryUsageName100.
00.
000.
000.
010.
010.
010.
012000.
00010.
00010foo0.
00.
000.
000.
000.
000.
000.
0010.
00000.
00000test_class->set_var20.
00.
000.
000.
000.
000.
000.
0010.
00000.
00000test_class->set_var10.
00.
000.
000.
000.
000.
000.
0010.
00000.
00000test_class->set_var30.
00.
000.
000.
000.
000.
000.
0010.
00000.
00000test_class->set_var40.
00.
000.
000.
000.
000.
000.
0010.
00000.
00000var_dump0.
00.
000.
000.
000.
000.
000.
0010.
00000.
00000test_class->disp0.
00.
000.
000.
000.
000.
000.
0010.
00000.
00000test_class->test_class0.
00.
000.
000.
000.
000.
000.
0010.
00000.
00000main0.
00.
000.
000.
000.
000.
000.
00260.
00000.
00000strtoupper0.
00.
000.
000.
000.
000.
000.
00520.
00000.
00000substr0.
00.
000.
000.
000.
000.
000.
0010.
00000.
00000implode0.
00.
000.
000.
000.
000.
000.
0020.
00000.
00000include0.
00.
010.
010.
000.
000.
000.
0020.
00000.
00000range0.
00.
000.
000.
000.
000.
000.
0010.
00000.
00000explodeTracefor/home/rasmus/phpweb/index.
phpTotalElapsedTime=0.
69TotalSystemTime=0.
01TotalUserTime=0.
08RealUserSystemsecs/cumm%Time(excl/cumm)(excl/cumm)(excl/cumm)Callscalls/callMemoryUsageName33.
30.
110.
130.
020.
030.
010.
0170.
00430.
0057298336require_once22.
20.
020.
020.
020.
020.
000.
001830.
00010.
0001-33944feof11.
10.
010.
010.
010.
010.
000.
0030.
00330.
0033-14808define11.
10.
040.
040.
010.
010.
000.
001820.
00010.
0001112040fgetcsv11.
10.
250.
250.
010.
010.
000.
0060.
00170.
00173768getimagesize11.
10.
010.
010.
010.
010.
000.
00550.
00020.
00022568sprintf0.
00.
000.
000.
000.
000.
000.
0070.
00000.
0000-136printf0.
00.
000.
000.
000.
000.
000.
0010.
00000.
0000136htmlspecialchars0.
00.
000.
000.
000.
000.
000.
0010.
00000.
0000-16mirror_provider_url0.
00.
000.
000.
000.
000.
000.
0070.
00000.
0000112spacer0.
00.
000.
000.
000.
000.
000.
00100.
00000.
0000-552delim0.
00.
000.
000.
000.
000.
000.
0010.
00000.
0000112mirror_provider0.
00.
000.
000.
000.
000.
000.
00200.
00000.
0000-624print_link-72-0.
00.
000.
000.
000.
000.
000.
0010.
00000.
000024have_stats0.
00.
000.
000.
000.
000.
000.
0010.
00000.
0000-72make_submit0.
00.
000.
000.
000.
000.
000.
0020.
00000.
0000112strrchr0.
00.
080.
080.
000.
000.
000.
0020.
00000.
0000168filesize0.
00.
000.
000.
000.
000.
000.
0010.
00000.
0000-16commonfooter0.
00.
000.
110.
000.
000.
000.
0020.
00000.
00000download_link0.
00.
000.
250.
000.
010.
000.
0060.
00000.
0017208make_imageXdebugcanprofileaswell:http://www.
xdebug.
org/docs-profiling.
php-73-Slide60/62January132004xdebugInstallingXdebugpear-vinstallhttp://files.
derickrethans.
nl/xdebug-1.
3.
0.
tgz+createdir/usr/local/lib/php/docs/xdebug52sourcefiles,buildingbuildingin/tmp/tmpH4fmdM/xdebug-1.
3.
0running:phpizeConfiguringfor:PHPApiVersion:20020918ZendModuleApiNo:20020429ZendExtensionApiNo:20021010buildingin/var/tmp/pear-build-root/xdebug-1.
3.
0running:/tmp/tmpH4fmdM/xdebug-1.
3.
0/configurecheckingbuildsystemtype.
.
.
i686-redhat-linux-gnucheckinghostsystemtype.
.
.
i686-redhat-linux-gnucheckingforgcc.
.
.
gcccheckingforCcompilerdefaultoutput.
.
.
a.
out.
.
.
BuildprocesscompletedsuccessfullyInstalling'xdebug.
so'atext_dir(/usr/local/lib/php/extensions/no-debug-non-zts-20020429/xdebug.
so)abouttocommit16fileoperationssuccessfullycommitted16fileoperationsinstallok:xdebug1.
3.
0StacktraceOutput:FunctiontraceTime#FunctionLocationMemory7.
925359->a()/home/rasmus/phpweb/pres2/display.
php(1539):eval()'dcode:929785607.
925380->b()/home/rasmus/phpweb/pres2/display.
php(1539):eval()'dcode:42978560ModifiederrorhandlerOutput:Notice:Undefinedvariable:ain/home/rasmus/phpweb/pres2/display.
php(1539):eval()'dcodeonline2CallStack#FunctionLocation1{main}()/home/rasmus/phpweb/pres2/show.
php:02_presentation->display()/home/rasmus/phpweb/pres2/show.
php:1043pdfa4->_presentation()/home/rasmus/phpweb/pres2/objects.
php:1244_example->display()/home/rasmus/phpweb/pres2/display.
php:1124-74-5pdfa4->_example()/home/rasmus/phpweb/pres2/objects.
php:1246eval()/home/rasmus/phpweb/pres2/display.
php:1539Modifiedvar_dump()Output:array'dims'=>'1024_705''LAST_SEARCH'=>'quickref,pres2/presentations/slides/php5intro/private.
xml''LAST_LANG'=>'en''PHPSESSID'=>'5bf70a24dc6723b683c3c212fd2b0600''COUNTRY'=>'NA,127.
0.
0.
1'-75-Slide61/62January132004Stop!
Oneofthemostimportantaspectsofperformancetuningandevenprogrammingingeneralisknowingwhentostop.
Gettingyourwebsiteorproductintothehandsofthecustomerisafterallthegoalofallthis.
Ifyousitaroundandfiddlewithitformonths,nobodyisusingit.
Onceyouhavelocatedallthelow-hangingfruit,furtheroptimizationtendstogetexponentiallyharderforlessandlessgain.
Thetimeyouspendonitcomparedtosimplybuyinganotherserverortwoisusuallynotworthit.
Stopandmoveontothenextproject.
Orbetteryet,gohome,spendsometimeawayfromthesebeastlycomputersandspendsometimewithyourwifeand/orkids-76-Slide62/62January132004ResourcesHomePage:http://www.
php.
netManual:http://php.
net/manualBooks:http://php.
net/books.
phpBugs:http://bugs.
php.
netPEAR:http://pear.
php.
netPECL:http://pecl.
php.
netXdebug:http://xdebug.
org-77-IndexManyThings2TemplateSystem3PHPisBig!
4KillerApps!
5Server-Side6EmbeddingPHP7gdchart8PDFson-the-fly13Ming-Flash15PEARExamples16PECL18Setup19SanityCheck20ConnectingtoMySQL21PersistentConnections22CreatingaDatabase23InsertingData24SelectingData25Dealingwithtimestamps26ChangingExistingRows27MagicQuotes28Squid29SquidConfiguration30MySQLReplication31$PATH_INFO33ErrorDocument34Cool!
35FunkyCaching36AppArchitecture37SimplisticExample38SafeMode40Security41Security42Security43Security44Security45PHP5OO-References46PHP5OO-*structors47PHP5OO-Private48PHP5OO-Protected49PHP5OO-set/get50PHP5OO-call51PHP5OO-Exceptions52Streamsandfilters53PHP-AWK54DOMXMLload55SimpleXML56SimpleRDF57SQLite58SQLite59PHPOpcodeCaches60PHPOpcodeCaches61PHPOpcodeCaches62WhenToOptimize63Tuning64Benchmarking65BenchmarkingResults68BenchmarkingResults70ProfilingPHP71xdebug74Stop!
76Resources77
青果网络QG.NET定位为高效多云管理服务商,已拥有工信部颁发的全网云计算/CDN/IDC/ISP/IP-VPN等多项资质,是CNNIC/APNIC联盟的成员之一,2019年荣获国家高薪技术企业、福建省省级高新技术企业双项荣誉。那么青果网络作为国内主流的IDC厂商之一,那么其旗下美国洛杉矶CN2 GIA线路云服务器到底怎么样?官方网站:https://www.qg.net/CPU内存系统盘流量宽带...
数脉科技怎么样?数脉科技品牌创办于2019,由一家从2012年开始从事idc行业的商家创办,目前主营产品是香港服务器,线路有阿里云线路和自营CN2线路,均为中国大陆直连带宽,适合建站及运行各种负载较高的项目,同时支持人民币、台币、美元等结算,提供支付宝、微信、PayPal付款方式。本次数脉科技给发来了新的7月促销活动,CN2+BGP线路的香港服务器,带宽10m起,配置E3-16G-30M-3IP,...
螢光云官網萤光云成立于2002年,是一家自有IDC的云厂商,主打高防云服务器产品。在国内有福州、北京、上海、台湾、香港CN2节点,还有华盛顿、河内、曼谷等海外节点。萤光云的高防云服务器自带50G防御,适合高防建站、游戏高防等业务。本次萤光云中秋云活动简单无套路,直接在原有价格上砍了一大刀,最低价格16元/月,而且有没有账户限制,新老客户都可以买,就是直接满满的诚意给大家送优惠了!官网首页:www....
phpecho为你推荐
HALLMARK_PANCREAS_BETA_CELLSios11centrescss平板ipad模式ios8支持ipad重庆宽带测速重庆联通宽带测速的网址是好多呢?ipadwifiIPAD连上了WIFI,但是无法上网,急!!iphone连不上wifi苹果8p连接不了WiFiiphone连不上wifi我的苹果手机连不上无线,其它手机能,怎么回事?只是家里的连不上itunes备份怎样用itunes备份iphone
香港虚拟主机 vps侦探 域名服务dns的主要功能为 godaddy域名解析 lnmp 息壤主机 美国主机论坛 新世界电讯 丹弗 铁通流量查询 100x100头像 腾讯云分析 日本bb瘦 200g硬盘 刀片式服务器 域名评估 135邮箱 微软服务器操作系统 服务器是干什么用的 空间登录首页 更多