Jump to content

Include/require Slow Down Sites?


danm68
 Share

Recommended Posts

A site of mine loads rather slowly, and I'm not sure whether it is the webhost, or the way I've designed my page with includes.Every page includes two sidebars, one for links and one for a calendar. The included links file will include another file if the user has the correct 'priveleges' and the same for the calendar.Looks like this:index |---navi | |---admin-opts | |---calendar | |---admin-cal-optsJust wondering if this counts as 2-4 extra http requests, or does someone know if including/requiring files increases load time. Both of the files are relatively small.If this is the case, would I be better off including one file with all my functions in it such as navigation(); and calendar(); and just calling those functions where I want them to appear on the page? Would that be faster? Or no real difference?Thanks,

Link to comment
Share on other sites

Includes and requires both result in one HTTP request, as the inclusion is done server-side, so the page is generated and then sent to the user.It is possible for a large PHP application to result in slow page requests, but this is usually because of other limitations like large database/network requests. Including something that's largely text should take almost no time at all (you can check if you need to with microtime()).What you suggest is very unlikely to give a significant speed boost, and makes it less convenient to maintain, so I wouldn't say that's a good move.The sluggish performance is likely the fault of the HTTPd (you might consider restarting it if it's your server), or latency between you and the host.EDIT: if it is just text, there is a slight speed increase by doing echo file_get_contents('/path/to/file'); rather than include, but it's not that significant, you'd be saving milliseconds.

Edited by AElliott
Link to comment
Share on other sites

The slow loading of your page is more likely due to the code that is received and interpretted on the client side. Maybe if you show a link to the site we can know better why it loads slowly.

Link to comment
Share on other sites

Thanks for the indepth explanation and info (includes are only one http request) and reply AElliot, rather enlightening :). Now I think the problem is the freehost I'm using and will also use microtime() to check out load times.And if your interested (probably mainly ingolme) site is beachhouse.110mb.comIt automatically goes to index, but because your not logged in it redirects you to login straight away(header("Location:login.php")). And login just displays form and time in top right corner which is php generated. That should be pretty quick yeah? Could it be loading slow only for me because the server is in canada (I think it said) and I'm in australia?Thanks again for the help and effort.

Edited by Reiyan
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...