Avatar billede swordcat Nybegynder
10. juli 2011 - 20:11 Der er 6 kommentarer og
1 løsning

Hjemmeside tager lang tid om at loade

Jeg har en hjemmeside som tit kan tage op til 5-10 sekunder om at loade, hvilket er til stor irritation. Nu er jeg ikke en kode-haj og jeg ved derfor ikke hvad jeg skal gøre for at rette op på problemet. Jeg har valgt at benytte mig at et CMS-system (CMS-Made Simple)og har webhotel hos One.com.

Jeg har downloadet et template som jeg har rettet til hist og pist, men jeg ved ikke hvor problemet ligger. Er der nogen der kan hjælpe?

Hjemmesiden er: www.spua.dk

Sig frem hvis du/I mangler info
Avatar billede magic-mouse Novice
10. juli 2011 - 21:02 #1
Hej har lige kigget nærmere på din side. Og det er tydeligt at det er billederne "content_bg.gif" og "footer_bg.gif" som tager noget tid at hente.

http://imageshack.us/f/818/spuatimeline.png/

Ud over det kan din index.php også tage en del tid har timet den fra 14 til 32 sekunder.

Skal bruge noget kode for at jeg kan se hvad fejlen er. Det virker som om at der er noget som tager en del tid at afvikle.
Avatar billede swordcat Nybegynder
10. juli 2011 - 21:07 #2
Har lavet et par test med Pingdom Tools som regner sig frem til, at det tager omkring 20-25 sekunder om at loade siden. Jo mere man surfer på hjemmesiden, desto mindre tid tager det om at loade siderne. Det er simpelthen for meget....hvad gør jeg?
Avatar billede swordcat Nybegynder
10. juli 2011 - 21:11 #3
Magic --> Sig frem. Hvad er det for en kode du har brug for?

Template-koden:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
{Statistics}
{autometa}
{metadata}
{autometa}
{content block='metatags'}
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>{sitename} - {title}</title>
{stylesheet}
</head>
<body>
<div id="container">
  <div id="header">
    <div id="logo_w1">Spua</div>
    <div id="logo_w2">En succesoplevelse</div>
    <div id="header_text">
      <p>Sammen kan vi styrke det præventive arbejde</p>
</div>
{menu number_of_levels="1" template="minimal_menu.tpl"}
  </div>
  <div id="content">
    <div id="left">
{content}
     
      <div id="photos"> <a href="http://www.spua.dk"><img src="images/photo1.jpg" alt="photo" /></a> </div>
   
</div>
   
<div id="right">
      <h2>Sidemenu</h2>
{menu start_level="2"}
          </div>
    <div id="footerline"></div>
  </div>
  <div id="footer">Copyright © 2011 Socialpædagogisk udviklingsarbejde. Alle rettigheder forbeholdes Spua</div>
</div>
</body>
</html>



Stylesheet:
body {
    background-color:#a6bf79;
    color:#000000;
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 12px;
    margin: 10px 10px;
    padding: 0px;
}
.clear{clear:both;}
* {
    margin: 0px;
    padding: 0px;
}
#container {
    margin: 0px auto;
    text-align: left;
    width: 717px;
}
a{
    font-size:12px;
}
p{
    margin: 15px 0px;
}
/********************** Header ***************************/
#header {
    margin: 0px 0px 0px 0px;
    background-image:url(images/header.jpg);
    width:717px;
    height:288px;
    position:relative;
}
#header ul{
    background-color:#85a157;
    width:711px;
    border: 3px solid #FFFFFF;
    display:block;
    top:255px;
    position:absolute;
    margin: 0px 0px 0px 0px;
    height:22px;
    padding:5px 0px 0px 0px;
    text-align:center;
}
#header li{
    display:inline;   
}
#header ul a{
    text-decoration:none;
    color:#FFFFFF;
    margin: 0px 15px;
}
#header ul a:hover{
    text-decoration:underline;
    color:#28556b;
}
#logo_w1,#logo_w2 {
    font-size: 24px;
    font-style:italic;
    color:#FFFFFF;
    position:absolute;
}
#logo_w1{
    top:15px;
    left:70px;
}
#logo_w2{
    top:44px;
    left:94px;
}
#header_text {
    top:90px;
    left:43px;
    width:230px;
    position:absolute;
}
#header_text p{
    font-size: 18px;
    color:#FFFFFF;
}
#header_text a{color:#28556b;}
#header_text a:hover{color:#c77e0c;}
/********************** Content ***************************/
#content {
    background-image:url(images/content_bg.gif);
    width:717px;
}
img{
    border-width:0px;
}
h1{
    color:#000000;
    font-size:14px;
    margin: 20px 0px 20px 0px;
}

h2{
    color:#85a157;
    font-size:14px;
    text-align:center;
    width:200px;
    margin: 10px 0px 15px 0px;
}
#left {
    float:left;
    width:428px;
    margin-left:27px;
    padding: 0px 10px 30px 0px;
    display:inline;
}
#left a{color:#28556b;}
#left a:hover{color:#c77e0c;}
#photos a{
    margin-right:14px;
}
#right {
    float:right;
    width:210px;
    padding: 0px 20px 20px 20px;
    margin-top:10px;
    border-left: #FFF 2px solid;

}
#right a{
    color:#c77e0c;
}
#right a:hover{
    color:#85a157;
}
/********************** Footer ***************************/
#footerline {
clear:both;
background-image:url(images/footer_bg.gif);
font-size:1px;
height:10px;
}
#footer {
    width:717px;
    text-align:center;
    padding: 20px 0px;
}
Avatar billede swordcat Nybegynder
10. juli 2011 - 21:18 #4
index.php:

<?php
#CMS - CMS Made Simple
#(c)2004 by Ted Kulp (wishy@users.sf.net)
#This project's homepage is: http://cmsmadesimple.sf.net
#
#This program is free software; you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation; either version 2 of the License, or
#(at your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.
#You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
#$Id: index.php 6369 2010-06-08 15:25:33Z calguy1000 $

$orig_memory = (function_exists('memory_get_usage')?memory_get_usage():0);
$dirname = dirname(__FILE__);
require_once($dirname.'/fileloc.php');

/**
* Entry point for all non-admin pages
*
* @package CMS
*/   

$starttime = microtime();
clearstatcache();


if (!isset($_SERVER['REQUEST_URI']) && isset($_SERVER['QUERY_STRING']))
{
    $_SERVER['REQUEST_URI'] = $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'];
}

if (!file_exists(CONFIG_FILE_LOCATION) || filesize(CONFIG_FILE_LOCATION) < 800)
{
    require_once($dirname.'/lib/misc.functions.php');
    if (FALSE == is_file($dirname.'/install/index.php')) {
        die ('There is no config.php file or install/index.php please correct one these errors!');
    } else {
        redirect('install/');
    }
}
else if (file_exists(TMP_CACHE_LOCATION.'/SITEDOWN'))
{
    echo "<html><head><title>Maintenance</title></head><body><p>Site down for maintenance.</p></body></html>";
    exit;
}

if (!is_writable(TMP_TEMPLATES_C_LOCATION) || !is_writable(TMP_CACHE_LOCATION))
{
    echo '<html><title>Error</title></head><body>';
    echo '<p>The following directories must be writable by the web server:<br />';
    echo 'tmp/cache<br />';
    echo 'tmp/templates_c<br /></p>';
    echo '<p>Please correct by executing:<br /><em>chmod 777 tmp/cache<br />chmod 777 tmp/templates_c</em><br />or the equivilent for your platform before continuing.</p>';
    echo '</body></html>';
    exit;
}

require_once($dirname.'/include.php');
// optionally enable output compression (as long as debug mode isn't on)
if( isset($config['output_compression']) && ($config['output_compression']) && $config['debug'] != true )
  {
    @ob_start('ob_gzhandler');
  }
else
  {
    @ob_start();
  }


$params = array_merge($_GET, $_POST);

$smarty = &$gCms->smarty;
$smarty->params = $params;

$page = get_pageid_or_alias_from_url();

$pageinfo = '';
if( $page == '__CMS_PREVIEW_PAGE__' && isset($_SESSION['cms_preview']) ) // temporary
  {
    $tpl_name = trim($_SESSION['cms_preview']);
    $fname = '';
    if (is_writable($config["previews_path"]))
      {
    $fname = cms_join_path($config["previews_path"] , $tpl_name);
      }
    else
      {
    $fname = cms_join_path(TMP_CACHE_LOCATION , $tpl_name);
      }
    $fname = $tpl_name;
    if( !file_exists($fname) )
      {
    die('error preview temp file not found: '.$fname);
    return false;
      }

    // build pageinfo
    $fh = fopen($fname,'r');
    $_SESSION['cms_preview_data'] = unserialize(fread($fh,filesize($fname)));
    fclose($fh);
    unset($_SESSION['cms_preview']);

    $pageinfo = PageInfoOperations::LoadPageInfoFromSerializedData($_SESSION['cms_preview_data']);
    $pageinfo->content_id = '__CMS_PREVIEW_PAGE__';
  }

if( !is_object($pageinfo) )
  {
    $pageinfo = PageInfoOperations::LoadPageInfoByContentAlias($page);
  }

// $page cannot be empty here
if (isset($pageinfo) && $pageinfo !== FALSE)
{
    $gCms->variables['pageinfo'] =& $pageinfo;

    if( isset($pageinfo->template_encoding) &&
        $pageinfo->template_encoding != '' )
    {
      set_encoding($pageinfo->template_encoding);
    }

    if($pageinfo->content_id > 0)
    {
        $manager =& $gCms->GetHierarchyManager();
        $node =& $manager->sureGetNodeById($pageinfo->content_id);
        if(is_object($node))
        {
          $contentobj =& $node->GetContent(true,true,false);
          if( !$contentobj->IsViewable() )
            {
              $url = $contentobj->GetURL();
              if( $url != '' && $url != '#' )
            {
              redirect($url);
            }
            }
          if( is_object($contentobj) )
            {
              $smarty->assign('content_obj',$contentobj);
            }
        }
    }

    $gCms->variables['content_id'] = $pageinfo->content_id;
    $gCms->variables['page'] = $page;
    $gCms->variables['page_id'] = $page;

    $gCms->variables['page_name'] = $pageinfo->content_alias;
    $gCms->variables['position'] = $pageinfo->content_hierarchy;
    global $gCms;
    $contentops =& $gCms->GetContentOperations();
    $gCms->variables['friendly_position'] = $contentops->CreateFriendlyHierarchyPosition($pageinfo->content_hierarchy);

    $smarty->assign('content_id', $pageinfo->content_id);
    $smarty->assign('page', $page);
    $smarty->assign('page_id', $page);
    $smarty->assign('page_name', $pageinfo->content_alias);
    $smarty->assign('page_alias', $pageinfo->content_alias);
    $smarty->assign('position', $pageinfo->content_hierarchy);
    $smarty->assign('friendly_position', $gCms->variables['friendly_position']);
}
else
// else if (get_site_preference('enablecustom404') == '' || get_site_preference('enablecustom404') == "0")
{
    ErrorHandler404();
    exit;
}

$html = '';
$cached = '';
$showtemplate = true;

if ((isset($_REQUEST['showtemplate']) && $_REQUEST['showtemplate'] == 'false') ||
    (isset($smarty->id) && $smarty->id != '' && isset($_REQUEST[$smarty->id.'showtemplate']) && $_REQUEST[$smarty->id.'showtemplate'] == 'false'))
{
  $showtemplate = false;
}


if (isset($_GET["print"]))
{
    ($smarty->is_cached('print:'.$page, '', $pageinfo->template_id)?$cached="":$cached="not ");
    $html = $smarty->fetch('print:'.$page, '', $pageinfo->template_id) . "\n";
}
else
{
    #If this is a case where a module doesn't want a template to be shown, just disable caching
        if( !$showtemplate )
    {
        $html = $smarty->fetch('template:notemplate') . "\n";
    }
    else
    {
        $smarty->caching = false;
        $smarty->compile_check = true;
        ($smarty->is_cached('template:'.$pageinfo->template_id)?$cached="":$cached="not ");

        // we allow backward compatibility (for a while)
        // for people that have hacks for setting page title
        // or header variables by capturing a modules output
        // to a smarty variable, and then displaying it later.
        if( isset($config['process_whole_template']) && $config['process_whole_template'] === false )
          {
            $top  = $smarty->fetch('tpl_top:'.$pageinfo->template_id);
            $body = $smarty->fetch('tpl_body:'.$pageinfo->template_id);
            $head = $smarty->fetch('tpl_head:'.$pageinfo->template_id);
            $html = $top.$head.$body;
          }
        else
          {
            $html = $smarty->fetch('template:'.$pageinfo->template_id);
          }
    }
}

#if ((get_site_preference('enablecustom404') == '' || get_site_preference('enablecustom404') == "0") && (!$config['debug']))
#{
#    set_error_handler($old_error_handler);
#}

#if (!$cached)
#{
    #Perform the content postrendernoncached callback
#    reset($gCms->modules);
#    while (list($key) = each($gCms->modules))
#    {
#        $value =& $gCms->modules[$key];
#        if ($gCms->modules[$key]['installed'] == true &&
#            $gCms->modules[$key]['active'] == true)
#        {
#            $gCms->modules[$key]['object']->ContentPostRenderNonCached($html);
#        }
#    }
  // this event doesn't exist in 1.7.x
    //Events::SendEvent('Core', 'ContentPostRenderNonCached', array(&$html));
#}

#Perform the content postrender callback
#reset($gCms->modules);
#while (list($key) = each($gCms->modules))
#{
#    $value =& $gCms->modules[$key];
#    if ( isset($gCms->modules[$key]['installed']) &&
#        $gCms->modules[$key]['installed'] == true &&
#        $gCms->modules[$key]['active'] == true)
#    {
#        $gCms->modules[$key]['object']->ContentPostRender($html);
#    }
#}

Events::SendEvent('Core', 'ContentPostRender', array('content' => &$html));

header("Content-Type: " . $gCms->variables['content-type'] . "; charset=" . (isset($pageinfo->template_encoding) && $pageinfo->template_encoding != ''?$pageinfo->template_encoding:get_encoding()));

echo $html;

@ob_flush();

$endtime = microtime();

$db =& $gCms->GetDb();

$memory = (function_exists('memory_get_usage')?memory_get_usage():0);
$memory = $memory - $orig_memory;
$memory_peak = (function_exists('memory_get_peak_usage')?memory_get_peak_usage():0);
if ( !is_sitedown() && $config["debug"] == true)
{
  echo "<p>Generated in ".microtime_diff($starttime,$endtime)." seconds by CMS Made Simple using ".(isset($db->query_count)?$db->query_count:'')." SQL queries and {$memory} bytes of memory (peak memory usage was {$memory_peak})</p>";
}
else if( isset($config['show_performance_info']) && ($showtemplate == true) )
{
echo "<!-- ".microtime_diff($starttime,$endtime)." / ".(isset($db->query_count)?$db->query_count:'')." / {$memory} / {$memory_peak} -->\n";

}

if( is_sitedown() || $config['debug'] == true)
{
    $smarty->clear_compiled_tpl();
    #$smarty->clear_all_cache();
}

if ( !is_sitedown() && $config["debug"] == true)
{
    #$db->LogSQL(false); // turn off logging
   
    # output summary of SQL logging results
    #$perf = NewPerfMonitor($db);
    #echo $perf->SuspiciousSQL();
    #echo $perf->ExpensiveSQL();

    #echo $sql_queries;
    foreach ($gCms->errors as $error)
    {
        echo $error;
    }
}

if( $page == '__CMS_PREVIEW_PAGE__' && isset($_SESSION['cms_preview']) ) // temporary
  {
    unset($_SESSION['cms_preview']);
  }
# vim:ts=4 sw=4 noet
?>
Avatar billede magic-mouse Novice
10. juli 2011 - 22:13 #5
Ok nu kommer det hårde arbejde.

Du skal efter hver funktion skrive en linie med et navn du kender igen så du kan finde stedet, samt timestamp.

Her et eksempel på et tilsvarende jeg har anvendt til et ligende problem.

2011-07-08 21:59:14 ==> GetJavas(i)
2011-07-08 22:07:46 ==> AddSub(0) : 1 : Start
2011-07-08 22:07:46 ==> ======================CONNECT=======================
2011-07-08 22:07:47 ==> AddSub(29) : 2 : Start
2011-07-08 22:07:47 ==> ======================CONNECT=======================
2011-07-08 22:07:48 ==> AddSub(73) : 3 : Start
2011-07-08 22:07:48 ==> ======================CONNECT=======================
2011-07-08 22:07:49 ==> AddSub(138) : 4 : Start
2011-07-08 22:07:49 ==> ======================CONNECT=======================
2011-07-08 22:07:49 ==> AddSub(138) : 3 : stop


Så kigger du på listen, og ser hvor er det der tager lang tid? I mit tilfælde var det mange database forbindelser der blev lavet hurtigt efter hinanden.

Men når du ved hvor det tager tid kan du forbedre på det område, enten ved at udbredre evt. fejl, optimere, tage beslutning om den funktion er vigtig og evt. fjerne den. Osv.

Det er meget arbejde, men desværre er det nødvendigt at vide hvor fejlen er.

Et eksempel i PHP er:

echo "Start" . date("H:i:s:u", time());
/* kode */
echo "funktion 1" . date("H:i:s:u", time());
/* kode */
echo "funktion 2" . date("H:i:s:u", time());
osv.
Avatar billede swordcat Nybegynder
11. juli 2011 - 05:33 #6
Det er helt sort det du har skrevet. Det er sikkert rigtig, men det siger mig intet, hvilket er lidt øv. Jeg kan desværre ikke nogen web-kode-sprog.

Måske det vil hjælpe, hvis jeg updater CMSMS-systemet? Det kunne jo være at de havde lavet en bedre index.php eller er jeg helt gal på den?
Avatar billede swordcat Nybegynder
13. juli 2011 - 11:12 #7
Lukker
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester