SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Zealot
    Join Date
    Sep 2005
    Location
    Perth, Australia
    Posts
    146
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

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

    I'm using the

    Code:
    <?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?

  2. #2
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    73 Post(s)
    Tagged
    0 Thread(s)
    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)
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  3. #3
    SitePoint Guru bronze trophy TomB's Avatar
    Join Date
    Oct 2005
    Location
    Milton Keynes, UK
    Posts
    996
    Mentioned
    9 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by StarLion View Post
    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.

  4. #4
    SitePoint Enthusiast bronze trophy \\.\'s Avatar
    Join Date
    Oct 2013
    Location
    UK
    Posts
    72
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    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.

  5. #5
    SitePoint Zealot
    Join Date
    Sep 2005
    Location
    Perth, Australia
    Posts
    146
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by \\.\ View Post
    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

  6. #6
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,889
    Mentioned
    74 Post(s)
    Tagged
    6 Thread(s)
    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.

    Quote Originally Posted by motion2082 View Post
    I'm using the

    Code:
    <?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?
    Learn how to be ready for The New Move to Discourse

    How to make Make Money Now with a *NEW* look

    Be sure to congratulate Wolfshade on earning Member of the Month for August 2014

  7. #7
    SitePoint Zealot
    Join Date
    Sep 2005
    Location
    Perth, Australia
    Posts
    146
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

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

    Code:
    <link rel="stylesheet" href="/css/theme.css">
    will make the site run faster?

  8. #8
    SitePoint Enthusiast bronze trophy \\.\'s Avatar
    Join Date
    Oct 2013
    Location
    UK
    Posts
    72
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    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.

  9. #9
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,889
    Mentioned
    74 Post(s)
    Tagged
    6 Thread(s)
    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


    Quote Originally Posted by motion2082 View Post
    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

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

    Code:
    <link rel="stylesheet" href="/css/theme.css">
    will make the site run faster?
    Last edited by John_Betong; Oct 15, 2013 at 03:48. Reason: added Pingdom link
    Learn how to be ready for The New Move to Discourse

    How to make Make Money Now with a *NEW* look

    Be sure to congratulate Wolfshade on earning Member of the Month for August 2014

  10. #10
    SitePoint Zealot
    Join Date
    Sep 2005
    Location
    Perth, Australia
    Posts
    146
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok thank you

  11. #11
    SitePoint Zealot
    Join Date
    Feb 2012
    Location
    United Kingdom
    Posts
    116
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    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.

  12. #12
    SitePoint Enthusiast bronze trophy \\.\'s Avatar
    Join Date
    Oct 2013
    Location
    UK
    Posts
    72
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •