Re: [PHP] Structuring large PHP programs
Joe, I believe that the concept of the Zend Cache shows the contrary. It basically pre-parses scripts and stores them in memory. Zend.com give figures up to 603% performance increase (http://www.zend.com/cguidemo/benchmark_frame.html). Part of this certainly is due to less disk access, the other part is the time that is saved in parsing the scripts. So, for a heavily-used application, the overhead in parsing code that is not needed is all but minimal. Ben Joe Stump wrote: Declaring the functions is minimal. Either your ISP has the memory allocations set unbearably low or you aren't coding things very well ... --Joe On Thu, Feb 15, 2001 at 04:16:22AM +0100, Ben Peter wrote: Hi Joe, the reason I changed to 'include on demand' was a rather large application which would not work, as the memory limit that my isp had set wouldn't suffice. I have files that are included all the way, yes: DB connection, some common helpers, etc. But I would not include files that the current state of an application (or part of the site) does not need to keep things small. This is especially true for some classes which before included both user access and 'admin' function (for, say, user authentication and administration). I split all of these up into two classes, so that the part that is accessed when a regular user hits the site is minimal, and the administrative functions won't be loaded in that case. Ben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] Structuring large PHP programs
A large application should be a set of well organized files having one single include at the top. And in that include you do all kind of things. Of course auto_prepend works always better /... but not always possible, right... use classes, reuse files ... libraries etc ... Cheers, Maxim Maletsky -Original Message- From: John McCreesh [mailto:[EMAIL PROTECTED]] Sent: Thursday, February 15, 2001 5:25 AM To: [EMAIL PROTECTED] Subject: [PHP] Structuring large PHP programs What is the best practice for structuring a PHP program which is becoming too large to manage as a single file? Should it be broken into a number of includes, e.g.: switch ($whatever) { case 0: include('case0.php'); break; case 1: include('case1.php'); break; case 2: include('case2.php'); break; } or a number of functions: require('mylib'); switch ($whatever) { case 0: case0(); break; case 1: case1(); break; case 2: case3(); break; } Any thoughts, references to articles (couldn't find anything in PHPBuilder), etc gratefully received... Thanks - John -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Structuring large PHP programs
John, part of this is a matter of taste - I would personally rather split this into functions. BUT: even if you _are_ using functions, you should only include() the file with the function when you need it, IF this part of the code is getting large. This way, php will not need to parse code that it won't need anyway. Ben John McCreesh wrote: What is the best practice for structuring a PHP program which is becoming too large to manage as a single file? Should it be broken into a number of includes, e.g.: switch ($whatever) { case 0: include('case0.php'); break; case 1: include('case1.php'); break; case 2: include('case2.php'); break; } or a number of functions: require('mylib'); switch ($whatever) { case 0: case0(); break; case 1: case1(); break; case 2: case3(); break; } Any thoughts, references to articles (couldn't find anything in PHPBuilder), etc gratefully received... Thanks - John -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Structuring large PHP programs
I'd go w/ functions. You can split the functions into as many files as needed but I wouldn't embed their inclusions in a switch statement. I'm not quite sure what you need the switch statement for so am assuming it's part of your applications logic. I'd never write a program as one giant clump of code. It should always be broken down into functions for easy growth and porting. :) John McCreesh wrote: What is the best practice for structuring a PHP program which is becoming too large to manage as a single file? Should it be broken into a number of includes, e.g.: switch ($whatever) { case 0: include('case0.php'); break; case 1: include('case1.php'); break; case 2: include('case2.php'); break; } or a number of functions: require('mylib'); switch ($whatever) { case 0: case0(); break; case 1: case1(); break; case 2: case3(); break; } Any thoughts, references to articles (couldn't find anything in PHPBuilder), etc gratefully received... Thanks - John -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Structuring large PHP programs
I would use a combination of both, Have all of your backend settings (including db info) in one include, and all of your user customisable settings (if you have any) in another include and finally another include for all your functions, so that any function is aviable at anytime. But this doesn't mean that you need to have three include() statements at the top of your page. Simply make refference to require('settings.inc'); then in this settings.inc file maintain all of your other includes to files. This way if you want to create another include, all you have to do is add it to settings.inc and then it is inlcuded in everyfile that settings.inc is included in! Scott Mebberson Redblue Design "John McCreesh" [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... What is the best practice for structuring a PHP program which is becoming too large to manage as a single file? Should it be broken into a number of includes, e.g.: switch ($whatever) { case 0: include('case0.php'); break; case 1: include('case1.php'); break; case 2: include('case2.php'); break; } or a number of functions: require('mylib'); switch ($whatever) { case 0: case0(); break; case 1: case1(); break; case 2: case3(); break; } Any thoughts, references to articles (couldn't find anything in PHPBuilder), etc gratefully received... Thanks - John -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Structuring large PHP programs
The way I normally do it is I have ONE main include (usually init.inc) and then all files that I might need throught my page I put in init.inc I works nicely for me. --Joe On Wed, Feb 14, 2001 at 09:15:35PM +0100, Ben Peter wrote: John, part of this is a matter of taste - I would personally rather split this into functions. BUT: even if you _are_ using functions, you should only include() the file with the function when you need it, IF this part of the code is getting large. This way, php will not need to parse code that it won't need anyway. Ben John McCreesh wrote: What is the best practice for structuring a PHP program which is becoming too large to manage as a single file? Should it be broken into a number of includes, e.g.: switch ($whatever) { case 0: include('case0.php'); break; case 1: include('case1.php'); break; case 2: include('case2.php'); break; } or a number of functions: require('mylib'); switch ($whatever) { case 0: case0(); break; case 1: case1(); break; case 2: case3(); break; } Any thoughts, references to articles (couldn't find anything in PHPBuilder), etc gratefully received... Thanks - John -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- --- Joe Stump, PHP Hacker, [EMAIL PROTECTED] -o) http://www.miester.org http://www.care2.com /\\ "It's not enough to succeed. Everyone else must fail" -- Larry Ellison _\_V --- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] Structuring large PHP programs
do you include EVERY file in init.inc even if that script doesn't use it? So if you have a db.inc and it doesn't use the db at all...is it included? -Jonathan -Original Message- From: Joe Stump [mailto:[EMAIL PROTECTED]] Sent: Wednesday, February 14, 2001 5:11 PM To: Ben Peter Cc: John McCreesh; [EMAIL PROTECTED] Subject: Re: [PHP] Structuring large PHP programs The way I normally do it is I have ONE main include (usually init.inc) and then all files that I might need throught my page I put in init.inc I works nicely for me. --Joe On Wed, Feb 14, 2001 at 09:15:35PM +0100, Ben Peter wrote: John, part of this is a matter of taste - I would personally rather split this into functions. BUT: even if you _are_ using functions, you should only include() the file with the function when you need it, IF this part of the code is getting large. This way, php will not need to parse code that it won't need anyway. Ben John McCreesh wrote: What is the best practice for structuring a PHP program which is becoming too large to manage as a single file? Should it be broken into a number of includes, e.g.: switch ($whatever) { case 0: include('case0.php'); break; case 1: include('case1.php'); break; case 2: include('case2.php'); break; } or a number of functions: require('mylib'); switch ($whatever) { case 0: case0(); break; case 1: case1(); break; case 2: case3(); break; } Any thoughts, references to articles (couldn't find anything in PHPBuilder), etc gratefully received... Thanks - John -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- -- - Joe Stump, PHP Hacker, [EMAIL PROTECTED] -o) http://www.miester.org http://www.care2.com /\\ "It's not enough to succeed. Everyone else must fail" -- Larry Ellison _\_V -- - -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Structuring large PHP programs
Any particular reason you don't do something like: $whatever="blah"; include($whatever); This eliminates the need for potentially dozens of case/switch statements. If you're interested, we're developing a more structured way of handling this with classes, and I could demonstrate some of this to you and/or send you code examples. John McCreesh wrote: What is the best practice for structuring a PHP program which is becoming too large to manage as a single file? Should it be broken into a number of includes, e.g.: switch ($whatever) { case 0: include('case0.php'); break; case 1: include('case1.php'); break; case 2: include('case2.php'); break; } or a number of functions: require('mylib'); switch ($whatever) { case 0: case0(); break; case 1: case1(); break; case 2: case3(); break; } Any thoughts, references to articles (couldn't find anything in PHPBuilder), etc gratefully received... Thanks - John -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Structuring large PHP programs
Hi Joe, the reason I changed to 'include on demand' was a rather large application which would not work, as the memory limit that my isp had set wouldn't suffice. I have files that are included all the way, yes: DB connection, some common helpers, etc. But I would not include files that the current state of an application (or part of the site) does not need to keep things small. This is especially true for some classes which before included both user access and 'admin' function (for, say, user authentication and administration). I split all of these up into two classes, so that the part that is accessed when a regular user hits the site is minimal, and the administrative functions won't be loaded in that case. Ben Joe Stump wrote: Normally, yes. The chances of a page NOT accessing the db is slim at best. I generally keep them there because the speed lost on parsing function definitions is minute and I don't have to worry about including numerous files in each page - or worse going through 100's of pages and adding an include I need when I add new functionality! --Joe On Wed, Feb 14, 2001 at 05:16:52PM -0800, Jonathan Sharp wrote: do you include EVERY file in init.inc even if that script doesn't use it? So if you have a db.inc and it doesn't use the db at all...is it included? -Jonathan -Original Message- From: Joe Stump [mailto:[EMAIL PROTECTED]] Sent: Wednesday, February 14, 2001 5:11 PM To: Ben Peter Cc: John McCreesh; [EMAIL PROTECTED] Subject: Re: [PHP] Structuring large PHP programs The way I normally do it is I have ONE main include (usually init.inc) and then all files that I might need throught my page I put in init.inc I works nicely for me. --Joe On Wed, Feb 14, 2001 at 09:15:35PM +0100, Ben Peter wrote: John, part of this is a matter of taste - I would personally rather split this into functions. BUT: even if you _are_ using functions, you should only include() the file with the function when you need it, IF this part of the code is getting large. This way, php will not need to parse code that it won't need anyway. Ben John McCreesh wrote: What is the best practice for structuring a PHP program which is becoming too large to manage as a single file? Should it be broken into a number of includes, e.g.: switch ($whatever) { case 0: include('case0.php'); break; case 1: include('case1.php'); break; case 2: include('case2.php'); break; } or a number of functions: require('mylib'); switch ($whatever) { case 0: case0(); break; case 1: case1(); break; case 2: case3(); break; } Any thoughts, references to articles (couldn't find anything in PHPBuilder), etc gratefully received... Thanks - John -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- -- - Joe Stump, PHP Hacker, [EMAIL PROTECTED] -o) http://www.miester.org http://www.care2.com /\\ "It's not enough to succeed. Everyone else must fail" -- Larry Ellison _\_V -- - -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- --- Joe Stump, PHP Hacker, [EMAIL PROTECTED] -o) http://www.miester.org http://www.care2.com /\\ "It's not enough to succeed. Everyone else must fail" -- Larry Ellison _\_V --- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list ad
Re: [PHP] Structuring large PHP programs
Declaring the functions is minimal. Either your ISP has the memory allocations set unbearably low or you aren't coding things very well ... --Joe On Thu, Feb 15, 2001 at 04:16:22AM +0100, Ben Peter wrote: Hi Joe, the reason I changed to 'include on demand' was a rather large application which would not work, as the memory limit that my isp had set wouldn't suffice. I have files that are included all the way, yes: DB connection, some common helpers, etc. But I would not include files that the current state of an application (or part of the site) does not need to keep things small. This is especially true for some classes which before included both user access and 'admin' function (for, say, user authentication and administration). I split all of these up into two classes, so that the part that is accessed when a regular user hits the site is minimal, and the administrative functions won't be loaded in that case. Ben Joe Stump wrote: Normally, yes. The chances of a page NOT accessing the db is slim at best. I generally keep them there because the speed lost on parsing function definitions is minute and I don't have to worry about including numerous files in each page - or worse going through 100's of pages and adding an include I need when I add new functionality! --Joe On Wed, Feb 14, 2001 at 05:16:52PM -0800, Jonathan Sharp wrote: do you include EVERY file in init.inc even if that script doesn't use it? So if you have a db.inc and it doesn't use the db at all...is it included? -Jonathan -Original Message- From: Joe Stump [mailto:[EMAIL PROTECTED]] Sent: Wednesday, February 14, 2001 5:11 PM To: Ben Peter Cc: John McCreesh; [EMAIL PROTECTED] Subject: Re: [PHP] Structuring large PHP programs The way I normally do it is I have ONE main include (usually init.inc) and then all files that I might need throught my page I put in init.inc I works nicely for me. --Joe On Wed, Feb 14, 2001 at 09:15:35PM +0100, Ben Peter wrote: John, part of this is a matter of taste - I would personally rather split this into functions. BUT: even if you _are_ using functions, you should only include() the file with the function when you need it, IF this part of the code is getting large. This way, php will not need to parse code that it won't need anyway. Ben John McCreesh wrote: What is the best practice for structuring a PHP program which is becoming too large to manage as a single file? Should it be broken into a number of includes, e.g.: switch ($whatever) { case 0: include('case0.php'); break; case 1: include('case1.php'); break; case 2: include('case2.php'); break; } or a number of functions: require('mylib'); switch ($whatever) { case 0: case0(); break; case 1: case1(); break; case 2: case3(); break; } Any thoughts, references to articles (couldn't find anything in PHPBuilder), etc gratefully received... Thanks - John -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- -- - Joe Stump, PHP Hacker, [EMAIL PROTECTED] -o) http://www.miester.org http://www.care2.com /\\ "It's not enough to succeed. Everyone else must fail" -- Larry Ellison _\_V -- - -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- --- Joe Stump, PHP Hacker, [EMAIL PROTECTED] -o) http://www.miester.org http://www.care2.com /\\ "It's not enough to succeed. Everyone else must fail" -- Larry Ellison _\_V --- -- PHP Genera