<?php include('file.php); slowing my site down

I’m using the

<?php
include(file.php);
?>

script on my website but users are complaining that it is slowing my site down.

Is there a better way of calling snippets of repetitive code?

Define it as a function and call the function? (NOTE: I have done exactly 0 analysis on whether that would speed things up. It may be a problem of what’s IN file.php, rather than the include function)

If users are noticing it, it’s certainly something that the php file is doing slowly. Post the code for the file being included and we can help you speed it up.

If your “file.php” script is accessing files and scraping information per page hit, this would certainly impact on things.

Making the assumption that this is the case, would the data not be better off in a database rather than a CSV for example? Even if its a SQLite3 database, its certainly better than accessing a file.

Going to have a check all my links today, some are absolute (ie http://www.mysite.com) think this might be the issue. Server is fetching full URL instead of just the file

Have you tried Pingdoom Tools?

Pingdom reports the site in your signature to load 16 CSS files and about 20 JavaScript files.

Combining CSS files into one large file and removing all JavaScript files from the HTML head and placing them immediately before /body will make a difference to page loading.

Hi John,

I think I will try combining all my CSS files into one file like you said.

As far as my JS files go, they are all located at the bottom of the page already.

Do you think changing

<link rel="stylesheet" href="http://www.mysite.com/css/theme.css">

to

<link rel="stylesheet" href="/css/theme.css">

will make the site run faster?

Use of relative over absolute paths is an argument that can rage for ages, its personal choice at the end of the day, I prefer relative paths because they are tidier and if you move server or change your domain name then you don’t need to change the paths.

Some web developers make their paths absolute so as to make site code theft less appealing. Yes people do steal ideas, shocking isn’t it?

I also suggest that you write your CSS inclusion in to the browser rather than have PHP insert it.

Try both ways of linking your stylesheets and monitor the difference with “http://tools.pingdom.com/fpt/

Personally I do not think there will be a difference but there again it is not often I am right :slight_smile:

Ok thank you

I believe absolute paths are faster than relative paths since the latter need to be resolved by the web server around the document root. I doubt, however, that this is the cause for a noticeably slower web page. The only way we can help you is if you provide more information about what the “file.php” include actually does - or just provide the source code for it.

You also have to remember that the end user may be downloading with a torrent client and their bandwidth is choked or the node they are on has more users than the contention ratio which is causing a network issue over speed.

ISP’s work on the principle that not everyone will be online all together, so at certain times of the day you will have network slow downs and you will notice a huge service drop at times when TV programs tell people to visit a URL for something like a competition.

Generally you will have network problems with end users because it is the end user and someone on their branch of the node that feeds their service is eating most of the bandwidth ergo site slow downs as they will report.

The other side of the coin is that the server your site is on is over loaded with traffic because of a website that may be sharing or streaming video, you should take the issue up with your host citing that you have had complaints from people visiting your site that it has been slow to respond where it hasn’t before, timeouts occur and you spoke to someone in a web forum that has had experience in network administration (me) and they said that you (your ISP) should have a quick look to ensure than no one is running a torrent server or hosting a stream that is pulling the server down and eating excessive bandwidth, it could be possible that the server is overloaded in any case and you can request to be moved to another server which they will do if the server needs it. The biggest cause of server load is PHP and other server sides running excessively long scripts that not only eat memory but also clock cycles. You never know, the server may have a site thats been hacked and someone is having loads of fun!

So give them a poke, because some server farms will park websites that get very low numbers of request on to a server that remains dormant until its woken up.

In the mean time tell your visitors to stop moaning, you are investigating the problem.