Jump to content

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
Link to comment
https://forums.phpfreaks.com/topic/13666-php-performance/
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.
Link to comment
https://forums.phpfreaks.com/topic/13666-php-performance/#findComment-52999
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

Link to comment
https://forums.phpfreaks.com/topic/13666-php-performance/#findComment-53000
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.