文件大小会减慢php响应吗?

I currently use a one file design... where all my php code is in one index.php file, I have about 13,000 lines (~1mb) in one file, and it is starting to hang a little on load time... I was thinking it could be the file size, but I had always thought PHP is preprocessed on the server, so it doesn't matter what is in the other if statements, because it won't be rendered.

Below is an example of my index.php:

if ($_POST['action'] == 'view') {
    // code
} else if ($_POST['action'] == 'something') {
    // code
} else if ($_POST['action'] == 'otherthings') {
    // code
} else {
   // homepage
}

Questions:

  1. Am I losing any speed by having my code in one file? or does this not affect the speed at all?
  2. Are there any code layout/organizational styles that are more efficient for PHP? or does this not matter either?

As others have recommended, it's better to break this file into parts, for ease of maintainability as much as anything. One thing you might consider is using an opcode cache like APC as this will reduce the number of times the index.php file is parsed.

  1. No, the more consume time is I/O, as opening files. In your case, server open and read an unique file, it's optimized

  2. But, code is not maintenable, has cyclomatic complex, is not really testable... It's recommended to organize your code in breaking it into many files, with MVC Logic for example. You can also use a micro framework to help you organize your code around conventions. See http://silex.sensiolabs.org/ for example.

Every line you put needs to be parsed, so putting all code in a unique file affects to response time.

A very simple way to reorganize all it would be:

$action = $_POST['action'];
$path = 'path_to_your_application';

//you should put some validation about action, for example

$allowed_actions = (array of possible values of "action");
if(in_array($action, $allowed_actions) && file_exists($path.$action.".php"))) require($path.$action.".php");
else //homepage

or something like this :-)