dptr1988 Posted July 4, 2006 Share Posted July 4, 2006 On my website there is only one page, index.php. I was wondering if it would be faster to include another PHP script into the index.php rather then having the code in index.php. Which method is faster? Maybe this code can explain it better:[code]<?php// Method 1switch($_GET['page']){ case 'about': include '../about.php'; break; case 'links': include '../links.php'; break; default: include '../home.php'; }// Method 2switch($_GET['page']){ case 'about': // code to display the about page ... // end of about page break; case 'links': // code to display the links page ... // end of links page break; default: // code to display the home page ... // end of home page }?>[/code]I'm using this method because I don't want users to see what file they are accessing. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/13666-php-performance/ Share on other sites More sharing options...
effigy Posted July 4, 2006 Share Posted July 4, 2006 Honestly, I don't think it matters (as long as all the files are local). I typically use a mixture of the methods, 1 for large, complicated things; 2 for simple things. Quote Link to comment https://forums.phpfreaks.com/topic/13666-php-performance/#findComment-52997 Share on other sites More sharing options...
wildteen88 Posted July 4, 2006 Share Posted July 4, 2006 There'll be no difference between the two methods, well there will be but you will hardly notice the difference as there will probably be less than 0.001 secounds difference between the two methods. I'd rather go for method 1 as it splits the code up into more manageable bits as each page will be in its own file, therefore you dont have go through a large file to edit a few lines of code for a certain page, as well as keeping the switch statement clean and easier to read etc. Quote Link to comment https://forums.phpfreaks.com/topic/13666-php-performance/#findComment-52999 Share on other sites More sharing options...
snowdog Posted July 4, 2006 Share Posted July 4, 2006 I agree. It is running the same code, from the two files as it is from the one, so speed shouldnt be any different at all. The situation I use include is when I can have the same coding in a couple pages and dont want to copy and paste it over again and again. It is great if you have to make one change in the file and you only have to do it once instead of on a few pages.Snowdog Quote Link to comment https://forums.phpfreaks.com/topic/13666-php-performance/#findComment-53000 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.