FRIHOSTFORUMSSEARCHFAQTOSBLOGSCOMPETITIONS
You are invited to Log in or Register a free Frihost Account!


long php pages or include





inphurno
I have some small questions.
I am starting to combine many PHP scripts in one page that is like 3500 lines in total.

here are my question:

question #1: would the page load quicker with one very long script or one small script including a many other scripts with the sections of code?

question #2: If it is quicker to have one small script with a bunch of pages included depending on what the code does in this operation, is it quicker to put all of my various MySQL queries for this one page, in different files for the php script to call, or should i put them all in one file which the server may have to call many times for this and other pages? Which one would be better?

Thanks in advance
rvec
I think it would be much easier for you to put it all in different pages, and probably better for the server to only include/require code if it is needed. Although the differences might not be too big, it'll make it much easier for you to edit the code if it is in multiple files.

Also just as with the function in the other topic, try the different options with microtime at the start and end to see what is faster.
badai
actually for php source code it doesn't really matter. what will slow it down is its' output to transfer to client. if you have 10,000 lines code that write only 1 line, it should be faster than 1,000 that output 100 lines.

also, for php you can just put everything in 1 file, but it will be difficult for you to edit it later.

for script that will be process by client, it will be faster to load part by part, only when needed.
rvec
The thing that makes a big page load slower is not the php but the bandwidth and the browser, php is mostly fast enough to do all in 1000th of a second. For example, php can count to 100k in 0.2 sec (on a normal windows pc), but to display a page with all those numbers your browser needs a couple of sec.
The difference between 10k lines of code or 100k is x10, and if all lines of code would take as much time as the others the time would also be x10. So less lines would be better, but you should only start to worry about stuff like that if you have a lot of pageviews and the serverload starts to increase because of your site (or if you just want to have good php code).

I'd suggest using as less code and as fast as possibe when writing new scripts, but not rewrite/modify scripts for that 1/100th of a sec.
kv
Having multiple files makes it a bit slower -- may be by some millisecs -- but user won't even notice that kind of difference. What you have to consider is the maintenance of the source code. It would be horrible to maintain a 10k line, one file source compared to 10*1k lines files -- or even more files well structured in directory hierarchy.

I would go for multiple files even if took 0.5 secs more.
AftershockVibe
Computers are there to make your life easier. For trivial things like this, it isn't sensible to make life "easier" for the computer at your expense.

Network speeds are orders of magnitude slower than hard disk seek times anyway so there will be absolutely no noticable difference to a user.
pollux1er
My opinion is not to include or require, and worst to make more than 2 includes! It slows the server. I read in a book written by Kevin Tatroe and Rasmus Lerdorf that including more than 2 files make the server slow. By deduction, i assume that include makes the server slow. If you prefer your include, combine all your files and include them once!
Let me check it in the book and post it for you.
pollux1er
This is it:
From Programming PHP Chapter 13 Application Techniques page 297.

Quote:
"...
When you are combining functions into a code library, you should be careful to
maintain a balance between grouping related functions and including functions that
are not often used. When you include a code library in a page, all of the functions in
that library are parsed, whether you use them all or not. PHP’s parser is quick, but
not parsing a function is even faster. At the same time, you don’t want to split your
functions over too many libraries, so that you have to include lots of files in each
page, because file access is slow. "
rvec
please use quote tags, and use the edit button.

Also the book said nothing about how many is slow, it just states that loading useless code is bad and loading from a lot of different pages is just as bad.
Solution include up to 15 pages and group the functions into normal files which you can easily read and select the ones you need from (so you won't require unneeded code).
pollux1er
rvec wrote:
please use quote tags, and use the edit button.

Also the book said nothing about how many is slow, it just states that loading useless code is bad and loading from a lot of different pages is just as bad.
Solution include up to 15 pages and group the functions into normal files which you can easily read and select the ones you need from (so you won't require unneeded code).


Sorry for my behaviour.

I am a french. This won't be repeated unless.

Thank you.
inphurno
thanks for all your responses everyone, this helped a lot! i will give it a try and let you know...
DjMilez
Including/Requiring is a lot more... organized than having everything in one file.
Also good if you have different files that need the same function.
AOP Web Development
would be a good practice if you use require_once or include_once so that it won't conflict if there are same functions occurs. Smile
rvec
AOP Web Development wrote:
would be a good practice if you use require_once or include_once so that it won't conflict if there are same functions occurs. Smile

You don't always want that. And it's also not a good practice to rely on that. Require_once always uses more resources than just one require.
Tadtoad
You should use include whenever you can., just in case you have some sensitive information in the php script.
If someone saves your page onto his hard drive he won't be able to gain access to the sensitive info.
rvec
I don't think include or require would make a difference there. If you have sebnsitive info it would probably be better to use a require or some errors might come up about unset variables/functions/classes or division by null and stuff like that.
amperx
require include would be best, because it makes editing faster, makes your file organized, and it helps your share those functions/classes instead of locking it up in one single file
Fire Boar
Certainly, don't put everything on one page. Doing so will slow your script down a fair bit, unless you have a separate PHP script for every page or function on your site. Why? Because the functions you need to put in that script are all parsed by the PHP engine at runtime, and if you never use half of them, complete waste of time. Also, it's a LOT more organized and space-efficient to keep some common functions in separate files.
rvec
Fire Boar wrote:
Certainly, don't put everything on one page. Doing so will slow your script down a fair bit, unless you have a separate PHP script for every page or function on your site. Why? Because the functions you need to put in that script are all parsed by the PHP engine at runtime, and if you never use half of them, complete waste of time. Also, it's a LOT more organized and space-efficient to keep some common functions in separate files.

Parsing 1k of lines is faster than opening 2 files (include/require). So it's more about keeping it organized than speed. If you only want speed throw all you need in one file and copy/paste code to other files if you need it there instead of including it.
Related topics
Site Nav Suggestions...
Do we support php include and/or SSI?
[Resolved] Object Orientated PHP errors
problems for indexing php pages in google.
Master Tutorial on SEO
Managing php pages
PHP VS ASP
one line securing of php pages (login of users) (user auth)
How do i host my PHP pages?
Hey, space.frih.net is now AstroTwister.com. cool, eh?
PHP as site template?
Using php to change content of a .txt
PHP login script problem
HTML vs PHP pages?
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.