shedokan Posted July 21, 2008 Share Posted July 21, 2008 what is faster? including a lot of small files? or having it all in one big file? and I don't mean some files aren't used they are all used always. thanks, I really need a good answer. Quote Link to comment https://forums.phpfreaks.com/topic/115844-what-is-faster/ Share on other sites More sharing options...
.josh Posted July 21, 2008 Share Posted July 21, 2008 If the amount of info is the same (length of file overall) and everything is being included always, I really don't think there's a difference...everything is read and parsed just the same. I mean, that's kind of like saying you need to count 100 pebbles and you have two piles of 100 pebbles one is one giant pile the other is split up into 5's or even individually. Either way you have to count each pebble. Quote Link to comment https://forums.phpfreaks.com/topic/115844-what-is-faster/#findComment-595531 Share on other sites More sharing options...
MadTechie Posted July 21, 2008 Share Posted July 21, 2008 Humm probably one large one.. as it will be shorter as the include "file1.php"; wasn't added anyways yeah what Crayon Violent said Quote Link to comment https://forums.phpfreaks.com/topic/115844-what-is-faster/#findComment-595534 Share on other sites More sharing options...
shedokan Posted July 21, 2008 Author Share Posted July 21, 2008 so why a script I downloaded includes the same file(which gets something from the database) a lot of times instead of not including it at all? is it stupidity or really something? thanks. Quote Link to comment https://forums.phpfreaks.com/topic/115844-what-is-faster/#findComment-595537 Share on other sites More sharing options...
LemonInflux Posted July 21, 2008 Share Posted July 21, 2008 Using multiple files can be useful if you want a quick, efficient way of editing code (say, if you have a database file, an authorization file and an error file, you can make changes to each section without having to look through a long code). But really, using multiple files is for organization. If that's not important, make it all one file. Quote Link to comment https://forums.phpfreaks.com/topic/115844-what-is-faster/#findComment-595541 Share on other sites More sharing options...
Darklink Posted July 21, 2008 Share Posted July 21, 2008 They say with HTML, that if you include a CSS file it's slower than putting all the CSS in the HTML and the more CSS files you load, the slower the output is. I know it's not PHP, but I reckon it might be similar although if that's the case, it's an incredibly tiny and unnoticeable change. Quote Link to comment https://forums.phpfreaks.com/topic/115844-what-is-faster/#findComment-595545 Share on other sites More sharing options...
.josh Posted July 21, 2008 Share Posted July 21, 2008 yeah if you want to nickel and dime it, even though php has to process the same amount of code, doing include "wholefile.php"; is physically less than doing include "file1.php"; include "file2.php"; include "file3.php"; include "file4.php"; but we're talking 4 small statements vs. 1 small statement here.. I don't think you can even measure the difference in processing time... so why a script I downloaded includes the same file(which gets something from the database) a lot of times instead of not including it at all? is it stupidity or really something? thanks. Well I don't think we can really give you a solid answer without more information (like, what script, what file, what code, etc..) but if I had to take a guess I'd say it's probably some kind of resource file that connects to the database that is being included across various pages. But again, that's just a guess, since I'm not looking at it. Quote Link to comment https://forums.phpfreaks.com/topic/115844-what-is-faster/#findComment-595548 Share on other sites More sharing options...
shedokan Posted July 21, 2008 Author Share Posted July 21, 2008 but the problem is that the script icludes the same file about 3-4 times each page and that file connects to a database and echoes something. the script doesn't use require_once. Quote Link to comment https://forums.phpfreaks.com/topic/115844-what-is-faster/#findComment-595570 Share on other sites More sharing options...
.josh Posted July 21, 2008 Share Posted July 21, 2008 well then (again, just a guess, seeing as how I don't have the script in front of me) I'd say they poorly coded it. Quote Link to comment https://forums.phpfreaks.com/topic/115844-what-is-faster/#findComment-595730 Share on other sites More sharing options...
MadTechie Posted July 21, 2008 Share Posted July 21, 2008 but the problem is that the script icludes the same file about 3-4 times each page and that file connects to a database and echoes something. the script doesn't use require_once. Okay i used include to add functions to my PHP code but you can also just insert HTML.. for example <font size="2" face="Verdana"> <?php echo "Username: $UserName"; ?> </font> $UserName = "MadTechie"; I am lazy and have a table and want to add it here<?php include "userdetails.php"; ?> and here<?php include "userdetails.php"; ?> etc etc and here<?php include "userdetails.php"; ?> I am lazy and have a table and want to add it here<font size="2" face="Verdana"> Username: MadTechie </font> and here<font size="2" face="Verdana"> Username: MadTechie </font> etc etc and here<font size="2" face="Verdana"> Username: MadTechie </font> Thats a possible reason.. Just side tracking for a second.. in reply to Darklink post (below) i would like to point out the reason its better to include a CSS file is because when the page loads, it opens 1 connection for each file on the page (but no more than the browser will allow IE6 default is 4), ie CSS/JS/images etc, so if you had one large HTML file with CSS it will be downloaded via 1 connection but if you have HTML & CSS in different files the browser will open 2 connections, that makes downloading quicker but the main reason i find, is that once the files downloaded its cached.. (don't need to download again for awhile) so if you had a CSS file of 2k and 40 html files each using it.. it will only download it once (depending on the clients browser setup) thus saving you 78k (2k x 40)-2k) of downloads. PS this doesn't mean add all your CSS code to one file.. They say with HTML, that if you include a CSS file it's slower than putting all the CSS in the HTML and the more CSS files you load, the slower the output is. I know it's not PHP, but I reckon it might be similar although if that's the case, it's an incredibly tiny and unnoticeable change. Quote Link to comment https://forums.phpfreaks.com/topic/115844-what-is-faster/#findComment-595990 Share on other sites More sharing options...
.josh Posted July 21, 2008 Share Posted July 21, 2008 Yeah MadTechie I can see how that might be "useful" or at least *more* "useful" but shedokan says that the included file connects to the db and displays something, which I really don't see any kind of good design in doing that. Quote Link to comment https://forums.phpfreaks.com/topic/115844-what-is-faster/#findComment-595991 Share on other sites More sharing options...
MadTechie Posted July 21, 2008 Share Posted July 21, 2008 Yeah CV, I totally agree that its highly like it due to bad/lazy programming (Pre-OOP code) someone using the mysql to get the users details (whatever). I have see it done before. either way it may explain the logic the programmer guy was using Quote Link to comment https://forums.phpfreaks.com/topic/115844-what-is-faster/#findComment-595997 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.