Jump to content

what is faster?


shedokan

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.