Jump to content

Archived

This topic is now archived and is closed to further replies.

dptr1988

PHP performance

Recommended Posts

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 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

}

?>
[/code]

I'm using this method because I don't want users to see what file they are accessing.
Thanks

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.