Jump to content


Photo

PHP performance


  • Please log in to reply
3 replies to this topic

#1 dptr1988

dptr1988
  • Members
  • PipPipPip
  • Advanced Member
  • 372 posts

Posted 04 July 2006 - 06:59 PM

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:
<?php

// Method 1
switch($_GET['page'])
{

 case 'about':
  include '../about.php';
  break;
 case 'links':
  include '../links.php';
  break;
 default:
  include '../home.php';
 
}

// Method 2
switch($_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
 
}

?>

I'm using this method because I don't want users to see what file they are accessing.
Thanks
Need more help with your project? One of the thousands of programmers, web designers or artists at <a href="http://www.rentacode...d_6764522">Rent A Coder</a> would be happy to help.

Disclaimer: Free advice is usually worth what you paid for it. ( or at least when it's coming from me! )

#2 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 04 July 2006 - 07:06 PM

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.
Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/

#3 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 04 July 2006 - 07:07 PM

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.

#4 snowdog

snowdog
  • Members
  • PipPipPip
  • Advanced Member
  • 107 posts

Posted 04 July 2006 - 07:08 PM

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






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users