elseif和5000行代码。 elseif是否与处理时间有所不同

Hello to everyone on this WONDERFUL site!!!!

I am in the process of coding a php script and it is expected to have over 5000 lines of code when finished. Each 100 lines or so will be broken up by esleif's so only about 100 lines will need to be processed when it runs.

My question is does php precess every line or will it literally skip if the conditions are not met? I want to know if it makes a difference in processing time. Is one large file broken up with elseif's the same as multiple files?

Thank you all in advance!

PHP will have to look at all code before it starts. Having it in a big file might be quicker, but one helluva kahuna to maintain.

  • Consider control statements like switch if you're writing lots of if..else.. stuff.
  • Consider caching plugins to speed stuff up
  • Consider code redundancy, using functions and modularising code. From your description, I've an awful vision of a main() with 5000 lines, which will be a nightmare to pick up in 6 months' time

The skipped lines will still need to be parsed and compiled, which can result in a significant overhead of done for each execution of the script.

However, if you use a PHP accelerator that caches the compiled bytecode, this overhead will disappear completely.

PHP will preprocess all of your code indeed, and compile it to memory. Then, only the part where conditions are met will be executed.

So loading thousands of lines of code is slower than loading a few ones, but loading a big php file is faster than loading many small ones, because of disk accesses.