Re: rewrite.php or redirect.php

From: Date: Mon, 08 Jan 2001 12:08:19 +0000
Subject: Re: rewrite.php or redirect.php
Groups: php.general 
Request: Send a blank email to php-general+get-33209@lists.php.net to get a copy of this message
Addressed to: Tino Hendricks <t.hendricks@interpool-online.de> <php-general@lists.php.net> ** Reply to note from Tino Hendricks <t.hendricks@interpool-online.de> Mon, 08 Jan 2001 09:45:33 +0100 > > I know how to do both ways codewise, I'm still not shure which way > would be more performant? > I would guess the 404 error handler will not care how many different possibilities you have. As you increase the number of different rewrite rules in your list it will take longer and longer to scan the list. For a small number of rules rewrite will be faster, but at some point the 404.php handler will catch up. Just a guess though. The best way to find out which performs better is to try both and time them. One good way to execute multiple hits is the ab program that comes with apache. ab -n 100 http://hostname.domain.tld/file/to/hit.php will hit the desdired web page 100 times and give you a summary of the times and some other good info. ab -h will give you a list of program options. Be sure to have a reasonable number of rewrite rules defined for the test that uses it, and make sure they are not defined when you are testing the 404 handler. It is quite possible a large rewrite list will affect all page hits on the server. > Because I want to make "standard" PHP files, which reside in some > "..../default/" directory. But I want to be able to replace or > overwrite these standard files - whereever necessary - with > customized ones: be the reason language (".../default/en" or > ".../default/de"), or customization > demands from customer (".../company1/" or ".../company2/"). You might be interested in something I am doing with the include_path of php: My include path is: /web/lib/pre:./:/web/lib/post In the DocumentRoot of sites I put small files that call common code. One of the initial files might look like: calendar.php ------------------------------------------------------ <? $BodyTag = 'bgcolor="$FFFFFF" textcolor="$000000" ' . 'background="/images/background.gif"'; $HeaderFile = '/header.page'; $FooterFile = '/footer.page'; $PageTitle = 'My Calendar Page'; $FontFace = 'Arial,Helvetica,sans-serif,Verdana'; $Color1 = "#FFFF00"; $Color2 = "$FF00FF"; include( 'calendar.plib' ); ?> ------------------------------------------------------ The calendar.plib file lives in /web/lib/pre, and is always hit whenever anyone includes calendar.plib because it appears before ./ in the include path. calendar.plib ------------------------------------------------------ <? # This file includes almost all of the code needed to # implement the calendar function, and none of the # html needed to display it. include( 'commoncode.plib' ); $Months = array( 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ); $Years = array( 1999, 2000, 2001, 2002, 2003, 2004, 2005 ); function GetDays( $Week ) { # This function handles one week, and uses PaintDay # to present the result. while( ... ) { ... ... paintDay( $Date, $Text, $Color1, $Color2 ); } } function GetCalendar( $Month, $Year ) # This function handles the month, and calls paint week # to display the data for one week. .. .. .. } # The last thing this file does is include the display code include( 'calendar.page' ); ?> ------------------------------------------------------ calendar.page ------------------------------------------------------ <? function PaintDay( $Date, $Text, $Color1, $Color2 ) { global $FontFace; ?> <TD bgcolor="<?=$Color1?> align=center> <font face="<?=$FontFace?>" color="<?=$Color2?>" Size=6> <?=$Date?> </font> <HR> <font face="<?=$FontFace?> size=2> <?=$Text?> </font> <HR> <? } function PaintWeek( $Color1, $Week ) { ?> <TR bgcolor=<?=$Color1?>> <? GetDays( $Week ) ?> </TR> <? } # Main page body starts here! ?> <!doctype html public ...> <HTML> <HEAD> <Title><?=$PageTitle?></TITLE> </HEAD> <BODY <?=$BodyTag?>> <? include( "$DOCUMENT_ROOT$HeaderFile" ) ?> <H1><?=$PageTitle?></H1> <TABLE> <? GetCalendar( $Month, $Year ) ?> </TABLE> <FORM Action=<?=$PHP_SELF?> method=post> <? SelectValue( 'Month:', 'Month', $Months ) ?> &nbsp;&nbsp;&nbsp;&nbsp; <? SelectField( 'Year:', 'Year', $Years ) ?><BR> <? SubmitButton( "Select" ) ?> </FORM> <? include( "$DOCUMENT_ROOT$FooterFile" ) ?> </BODY> </HTML> ------------------------------------------------------ The .page file focuses on presentation, with very little program code in it. It is placed in /web/lib/post which appears after ./ in the include path. Most of the time when someone wants to use the calendar I provide all they have to do is setup the body tag, font faces and colors in a copy of the .php file I provide. That file calls the .plib file from the lib/pre/ directory which handles the program logic and includes calendar.page. Since the .plib file is in the pre directory they can not override it by having an alternate file in their directory. The calendar.page is in the post directory and can be overridden by a calendar.page file in the directory with the calendar.php file. Most of the time it is not needed, but if the customer wants to do something very special with the calendar they can probably just make a copy of the calendar.page file from lib/post/ and make the needed changes in their directory. These changes will only affect their web site. It looks like a lot of includes, but my actual implementation is acltually worse, and I still see < 0.1 second total time per page on the fastest pages like this. Of course the time is not nearly as good for pages that have to hit a database. Rick Widmer Internet Marketing Specialists http://www.developersdesk.com

« previous php.general (#33209) next »