Forum Moderators: coopster

Message Too Old, No Replies

Using .inc vs. .php for includes.

Is there a speed difference?

         

HughMungus

6:17 pm on Dec 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I usually name my includes .php for security reasons but I was just wondering if naming an include .php will slow the page loading time since the server will check a .php file for executable scripts. Thoughts?

Salsa

6:37 pm on Dec 6, 2004 (gmt 0)

10+ Year Member



If the include contains no PHP, there's no harm in using a .inc extension, but I it will be parsed anyway when it's included in a PHP file, so I don't think it would save any server load. It's probably best to stick with your convention. I usually call my includes something.inc.php so I can easily see that they are includes.

DaButcher

7:00 pm on Dec 6, 2004 (gmt 0)

10+ Year Member



I usually stick to .php, but start the files with _ (underscore)..

eg:
_images.php

HughMungus

7:10 pm on Dec 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yeah, but what I'm asking is if the server checks every included file that has a .php extension for executable scripting (whether it has script in it or not) before including it (or does the execution happen only after it's included)?

jatar_k

7:20 pm on Dec 6, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



the hit on the server is nominal at best

Birdman

7:31 pm on Dec 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Actually, if you are simply importing straight data(no scripting) from the file, then readfile() will be faster and you can name them with .txt, .inc, etc.. Readfile() won't parse the file for PHP tags.

jollymcfats

8:30 pm on Dec 6, 2004 (gmt 0)

10+ Year Member



Yeah, but what I'm asking is if the server checks every included file that has a .php extension for executable scripting (whether it has script in it or not) before including it (or does the execution happen only after it's included)?

include() doesn't even look at the extension. It always loads the given file & parses it.

coopster

9:29 pm on Dec 6, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



True, somewhat (it looks at the extension so it knows which file to get, but not how to process it). include() [php.net] actually starts out in "HTML" mode, invoking PHP when it hits a start tag.


When a file is included, parsing drops out of PHP mode and into HTML mode at the beginning of the target file, and resumes again at the end. For this reason, any code inside the target file which should be executed as PHP code must be enclosed within valid PHP start and end tags [php.net].