[PHP] PHP Website Architecture
Hi all, I have a question regarding website design with PHP. Is it better to have a single PHP script produce different content or have a separate PHP script for every action. For example, if an error occurs, should I have the same PHP script produce an error page or have a separate PHP script produce the error page. I'm asking in reference to performance. Thanks! _ Is your PC infected? Get a FREE online computer virus scan from McAfee® Security. http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] PHP Website Architecture
[snip] I have a question regarding website design with PHP. Is it better to have a single PHP script produce different content or have a separate PHP script for every action. For example, if an error occurs, should I have the same PHP script produce an error page or have a separate PHP script produce the error page. I'm asking in reference to performance. [/snip] In reference to performance this shouldn't matter. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] PHP Website Architecture
On 5/7/2004 5:47:47 PM, Jay Blanchard ([EMAIL PROTECTED]) wrote: [snip] I have a question regarding website design with PHP. Is it better to have a single PHP script produce different content or have a separate PHP script for every action. For example, if an error occurs, should I have the same PHP script produce an error page or have a separate PHP script produce the error page. I'm asking in reference to performance. [/snip] If you are thinking only of performance this wont matter at all, but sometimes for the sake of simplicity and easier management of code it is good to split files for different tasks. Nearly all programs can be written in *one* very large .php file but just thinking of going back in to make changes 3 months down the road would be a nightmare. HTH. Cheers, -Ryan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] PHP Website Architecture
Ok, thanks. I didn't think it would make a difference. And I agree, splitting things up makes things a lot easier. Thanks! From: Ryan A [EMAIL PROTECTED] Reply-To: Ryan A [EMAIL PROTECTED] To: [EMAIL PROTECTED] Subject: RE: [PHP] PHP Website Architecture Date: Fri, 7 May 2004 17:51:45 +0200 On 5/7/2004 5:47:47 PM, Jay Blanchard ([EMAIL PROTECTED]) wrote: [snip] I have a question regarding website design with PHP. Is it better to have a single PHP script produce different content or have a separate PHP script for every action. For example, if an error occurs, should I have the same PHP script produce an error page or have a separate PHP script produce the error page. I'm asking in reference to performance. [/snip] If you are thinking only of performance this wont matter at all, but sometimes for the sake of simplicity and easier management of code it is good to split files for different tasks. Nearly all programs can be written in *one* very large .php file but just thinking of going back in to make changes 3 months down the road would be a nightmare. HTH. Cheers, -Ryan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php _ FREE pop-up blocking with the new MSN Toolbar get it now! http://toolbar.msn.com/go/onm00200415ave/direct/01/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re[2]: [PHP] PHP Website Architecture
Hello Ryan, Friday, May 7, 2004, 4:51:45 PM, you wrote: RA Nearly all programs can be written in *one* very large .php file but just RA thinking of going back in to make changes 3 months down the road would be a RA nightmare. I was just looking at this the other day - I had a local site running here and profiling the index page took around 800ms with 30 include files. Out of interest I dumped a load of those files into one and re-profiled it (11 includes rather than 300) and the load time dropped dramatically (300ms). I know there are other factors at play here (Windows vs. Unix, cached vs. needing to seek across the hard drive every time), but the difference still surprised me. Of course I could never cope with all of those files as one, but I will definitely keep them split up locally and combine into one when published live. -- Best regards, Richard Davey http://www.phpcommunity.org/wiki/296.html -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP Website Architecture
Ryan, et al -- ...and then Ryan A said... % % % On 5/7/2004 5:47:47 PM, Jay Blanchard ([EMAIL PROTECTED]) % wrote: [snip] Did you realize that you quoted Jay's quote of Paul's original note but then snipped off Jay's comment? :-) ... % If you are thinking only of performance this wont matter at all, but % sometimes for the sake of simplicity and easier management of code it is % good to split files for different tasks. Agreed. % Nearly all programs can be written in *one* very large .php file but just % thinking of going back in to make changes 3 months down the road would be a % nightmare. Now, now... If you structure your code effectively it's no harder to edit one large file than it is to edit a bunch of smaller files. I agree that sometimes breaking up is a good thing, but I haven't the slightest problem working in the single main (and large) script for our gallery engine, amongst other projects, and as an added bonus I don't have to remember in which file to search, months later, when I'm tracking a bug (er, reconsidered feature, since there are no bugs in my code! ;-) % % HTH. % % Cheers, % -Ryan HTH HAND :-D -- David T-G [EMAIL PROTECTED] http://justpickone.org/davidtg/ Shpx gur Pbzzhavpngvbaf Qrprapl Npg! pgp0.pgp Description: PGP signature
Re: Re[2]: [PHP] PHP Website Architecture
On Fri, 2004-05-07 at 12:00, Richard Davey wrote: Hello Ryan, Friday, May 7, 2004, 4:51:45 PM, you wrote: RA Nearly all programs can be written in *one* very large .php file but just RA thinking of going back in to make changes 3 months down the road would be a RA nightmare. I was just looking at this the other day - I had a local site running here and profiling the index page took around 800ms with 30 include files. Out of interest I dumped a load of those files into one and re-profiled it (11 includes rather than 300) and the load time dropped dramatically (300ms). I know there are other factors at play here (Windows vs. Unix, cached vs. needing to seek across the hard drive every time), but the difference still surprised me. Of course I could never cope with all of those files as one, but I will definitely keep them split up locally and combine into one when published live. I think there was a recent discussion on the internals list that mentioned how the realpath lookup for files is fairly slow and that it can have an impact :/ Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Profiling (Was: Re: [PHP] PHP Website Architecture)
Hi Richard, Just curious...how do you do your profiling? cheers, Travis Richard Davey wrote: Hello Ryan, Friday, May 7, 2004, 4:51:45 PM, you wrote: RA Nearly all programs can be written in *one* very large .php file but just RA thinking of going back in to make changes 3 months down the road would be a RA nightmare. I was just looking at this the other day - I had a local site running here and profiling the index page took around 800ms with 30 include files. Out of interest I dumped a load of those files into one and re-profiled it (11 includes rather than 300) and the load time dropped dramatically (300ms). I know there are other factors at play here (Windows vs. Unix, cached vs. needing to seek across the hard drive every time), but the difference still surprised me. Of course I could never cope with all of those files as one, but I will definitely keep them split up locally and combine into one when published live. -- Travis Low mailto:[EMAIL PROTECTED] http://www.dawnstar.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Profiling (Was: Re: [PHP] PHP Website Architecture)
Hello Travis, Friday, May 7, 2004, 7:06:03 PM, you wrote: TL Hi Richard, TL Just curious...how do you do your profiling? Zend IDE. View the page in IE, click the Profile button, analyse the pretty pie-charts and graphs and stack trace until I see where the bottle necks are :) -- Best regards, Richard Davey http://www.phpcommunity.org/wiki/296.html -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: PHP Website Architecture
Well if you really want to do it the perfect way, I would recommend using only one PHP file to generate the whole site. Or if you like, have one file with all the functions. You should also read into classess and create most of the functions as classess. To do the error handling there are many ways to go, but the best way would be to use output buffering. If an error occurs you can store the entire buffer if you like into a database and present an entire different page to the user informing that samoething went wrong. The old alternative is to present a 50/50 page with some error handling here and there. Its really all up to you, there isnt a perfect way in doing this. But my advice again, use classess (OOP) as its very reusable and look at output buffering for total control. -- -- Kim Steinhaug -- There are 10 types of people when it comes to binary numbers: those who understand them, and those who don't. -- www.steinhaug.com - www.easywebshop.no - www.webkitpro.com -- Paul Higgins [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Hi all, I have a question regarding website design with PHP. Is it better to have a single PHP script produce different content or have a separate PHP script for every action. For example, if an error occurs, should I have the same PHP script produce an error page or have a separate PHP script produce the error page. I'm asking in reference to performance. Thanks! _ Is your PC infected? Get a FREE online computer virus scan from McAfee® Security. http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Website Architecture
I've got a directory structure similar to this: SiteRootDir index.php dirA index.php dirB funcs.php otherfuncs.php In the SiteRootDir/index.php, I've got: require_once( dirB/funcs.php ); in funcs.php, I've got: require_once( otherfuncs.php ); which works because SiteRootDir/index.php is the location from which files are looked for. However, in dirA/index.php, I've got: require_once( ../dirB/funcs.php ); and require_once( otherfuncs.php ) in funcs.php cannot be found. A solution I found was in dirA/index.php, to chdir( .. ); before the require_once, which moves the current directory to SiteRootDir and allows otherfuncs.php to be found ... is this the best way to solve this problem? A seperate, but related question funcs.php contains statements of the form: echo a href=\directoryname\linkname/abr; forming a relative URL. Again, this would point to a different location depending on whether dirA/index.php or SiteRootDir/index.php called the function containing this relative URL and I want them to point to the same location. I was able to find a solution by doing the following: function AFunction( $toRoot ) { $location = $toRoot . locationFromSiteRootDir; echo a href=\$location\linkname/abr; } So, from dirA/index.php, I would call AFunction like: AFunction( .. ); Is this the best way to solve this problem? Thank you. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Website Architecture
The best way, IMHO, is to use absolute paths (from docroot, of course) whenever you include or require files. The same logic can be applied to the related problem of links. Shaunak -Original Message- From: Eric Gorr [mailto:[EMAIL PROTECTED] Sent: Thursday, February 05, 2004 4:35 PM To: [EMAIL PROTECTED] Subject: [PHP] Website Architecture I've got a directory structure similar to this: SiteRootDir index.php dirA index.php dirB funcs.php otherfuncs.php In the SiteRootDir/index.php, I've got: require_once( dirB/funcs.php ); in funcs.php, I've got: require_once( otherfuncs.php ); which works because SiteRootDir/index.php is the location from which files are looked for. However, in dirA/index.php, I've got: require_once( ../dirB/funcs.php ); and require_once( otherfuncs.php ) in funcs.php cannot be found. A solution I found was in dirA/index.php, to chdir( .. ); before the require_once, which moves the current directory to SiteRootDir and allows otherfuncs.php to be found ... is this the best way to solve this problem? A seperate, but related question funcs.php contains statements of the form: echo a href=\directoryname\linkname/abr; forming a relative URL. Again, this would point to a different location depending on whether dirA/index.php or SiteRootDir/index.php called the function containing this relative URL and I want them to point to the same location. I was able to find a solution by doing the following: function AFunction( $toRoot ) { $location = $toRoot . locationFromSiteRootDir; echo a href=\$location\linkname/abr; } So, from dirA/index.php, I would call AFunction like: AFunction( .. ); Is this the best way to solve this problem? Thank you. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Website Architecture
Eric Gorr wrote: A solution I found was in dirA/index.php, to chdir( .. ); before the require_once, which moves the current directory to SiteRootDir and allows otherfuncs.php to be found ... is this the best way to solve this problem? Qualify relative paths by prepending $_SERVER['DOCUMENT_ROOT'].'/' - I usually define a constant at the start of all scripts like so... define('SITE_ROOT', $_SERVER['DOCUMENT_ROOT'].'/'); forming a relative URL. Again, this would point to a different location depending on whether dirA/index.php or SiteRootDir/index.php called the function containing this relative URL and I want them to point to the same location. Why can't you specify an absolute URL? Thank you. You're welcome. -- Stuart -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Website Architecture
On Thu, Feb 05, 2004 at 09:48:22PM +, Stuart wrote: Eric Gorr wrote: A solution I found was in dirA/index.php, to chdir( .. ); before the require_once, which moves the current directory to SiteRootDir and allows otherfuncs.php to be found ... is this the best way to solve this problem? Qualify relative paths by prepending $_SERVER['DOCUMENT_ROOT'].'/' - I usually define a constant at the start of all scripts like so... define('SITE_ROOT', $_SERVER['DOCUMENT_ROOT'].'/'); Why not use php's include_path setting? No need to define constants, no need to worry about the location of your script relative to the document root, and it works with more functions than just include() and require(). I have found it to be the cleanest, most reliable, and most portable way to deal with file paths. joel -- [ joel boonstra | gospelcom.net ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Website Architecture
joel boonstra wrote: On Thu, Feb 05, 2004 at 09:48:22PM +, Stuart wrote: Eric Gorr wrote: A solution I found was in dirA/index.php, to chdir( .. ); before the require_once, which moves the current directory to SiteRootDir and allows otherfuncs.php to be found ... is this the best way to solve this problem? Qualify relative paths by prepending $_SERVER['DOCUMENT_ROOT'].'/' - I usually define a constant at the start of all scripts like so... define('SITE_ROOT', $_SERVER['DOCUMENT_ROOT'].'/'); Why not use php's include_path setting? No need to define constants, no need to worry about the location of your script relative to the document root, and it works with more functions than just include() and require(). I have found it to be the cleanest, most reliable, and most portable way to deal with file paths. joel And if document root is different from include path? What if the include path is outside of document root? You CANNOT rely on include_path to accomplish this. -- By-Tor.com It's all about the Rush http://www.by-tor.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Website Architecture
On Thu, Feb 05, 2004 at 04:35:14PM -0600, John Nichel wrote: snip And if document root is different from include path? What if the include path is outside of document root? You CANNOT rely on include_path to accomplish this. Sorry, I should have been more specific. I was implying that you would set the include_path to include your document_root for your whole site, using httpd.conf, .htaccess, or ini_set() (.htaccess probably being the easiest). # httpd.conf or .htaccess: php_value include_path '/path/to/document/root:.' # ini_set(): ini_set('include_path', {$_SERVER['DOCUMENT_ROOT']}:.); You could also modify the ini_set() method to append document_root to your current include_path setting, using the PHP_INCLUDE_PATH constant. I think. But you're right, you can't rely on the default include_path setting to contain anything useful. If you set it manually, though, it can contain whatever you want. Unless I'm misunderstanding what you're saying... joel -- [ joel boonstra | gospelcom.net ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Website Architecture
On Thu, Feb 05, 2004 at 05:42:54PM -0500, joel boonstra wrote: snip # ini_set(): ini_set('include_path', {$_SERVER['DOCUMENT_ROOT']}:.); Replying to myself, it appears that PHP = 4.3.0 has a family of functions specifically for tweaking include_path: http://www.php.net/manual/en/function.set-include-path.php When using ini_set() or something similar to tweak the include_path, I would recommend using it in conjunction with a file that is auto-prepended to all of your .php scripts (assuming you want all of your scripts to use the same include_path): # in .htaccess php_value auto_prepend_file path/to/init.php # init.php set_include_path('/new/include/path'); You can of course put other stuff that needs to apply to all .php files in init.php, too. joel -- [ joel boonstra | gospelcom.net ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php