berridgeab Posted September 8, 2009 Share Posted September 8, 2009 Hi I am writing quite a large web application which is going to grow larger and larger as it's purpose continues to expand.I was going through some old scripts, and optimizing them to use as least code as possible. One large script I have is called admin.php. Though the initial script runs through a small bit of code to determine which function to use. The acutal functions themselves are growing quite large and i'm worryed about the time PHP will take to parse the entire script. I have written an example down below of what it looks like in its basic form. <?php $Page = $_REQUEST['page']; switch ($Page) { case 'Page1': function 1(); break; case 'Page2': function 2(); break; case 'Page3': function 3(); break; } function 1() { //Lots of code and doing stuff } function 2() { //Lots of code and doing stuff } function 3() { //Lots of code and doing stuff } Basically my question is, say $Page matched Page1. Would only function 1() be parsed as the other functions are not required, or would PHP parse the entire including all it's functions (Even though there not required at the time). If the answer is Yes, then is there any way round this? Maybe spliting chunks of my script into different PHP files and just including them? (Like Below). Will this stop the unneeded bits of code being parsed? <?php $Page = $_REQUEST['page']; switch ($Page) { case 'Page1': include_once('admin_func1.php'); break; case 'Page2': include_once('admin_func2.php'); break; case 'Page3': include_once('admin_func3.php'); break; } Quote Link to comment https://forums.phpfreaks.com/topic/173529-solved-not-a-problem-just-an-explanation-needed-really/ Share on other sites More sharing options...
Mark Baker Posted September 8, 2009 Share Posted September 8, 2009 Parsing to bytecode is pretty quick, so not something you normally need to worry about. If it makes you feel better, you could probably split your functions into include files, but the overhead of searching for and reading the file would probably be greater than having them all in one file Quote Link to comment https://forums.phpfreaks.com/topic/173529-solved-not-a-problem-just-an-explanation-needed-really/#findComment-914682 Share on other sites More sharing options...
gr1zzly Posted September 8, 2009 Share Posted September 8, 2009 I'm not sure about the parsing but my guess is that it will parse all of the code. Seems to me like you have a better method already. If you do the select case to include() the script for each page as it's required not only will you compartmentalize your scripts making them easier to manage and update but the parsing issue becomes moot. Quote Link to comment https://forums.phpfreaks.com/topic/173529-solved-not-a-problem-just-an-explanation-needed-really/#findComment-914684 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.