Narc0t1CYM
Narc0t1CYM

Reputation: 622

High load time for website

Recently I've run into a problem with my website: It started to load really-really slow, and I had no idea why is it like this. I looked at it with the profiler, and found out that the ending of my URL - which is an ID passed by as a query string - takes around 13 seconds to load. I have no idea what is causing this. I checked the scripts, disabled them partly and all together but nothing seems to help. For e.g.: www.mysite.com/flat/5/

I read that sometimes if Chrome cannot find a content like an image, it takes a long time to load, but I have no missing files that chrome would like to load.

I'm attaching a screenshot to show you what does the profiler show: enter image description here

EDIT: Added the server-side code

<?php
include("header.php");

$flatType = (isset($_GET["flat_type"])) ? $_GET["flat_type"] : null;
$flatId = (isset($_GET["flat_id"])) ? $_GET["flat_id"] : null;

$sqlFlats = "SELECT * FROM lakasok a JOIN tanacsadok b ON (a.tanacsado_id = b.id) WHERE elado_kiado = '$flatType' AND a.id = '$flatId'";
$queryFlats = mysqli_query($con, $sqlFlats);

$flat = mysqli_fetch_assoc($queryFlats);

$district = ($flat["varos"] == "Budapest") ? $flat["kerulet"]." ".$lang["flat-single-district"] : "";
if ($flat["elado_statusz"] == 0 && $flatType == "elado") {
    $actual = '<b>'.$lang["flat-single-sell-available"].'</b> <span class="ft-thinest">/ '.$lang["flat-single-sell-unavailable"].'</span>';
} else if ($flat["kiado_statusz"] == 0 && $flatType == "kiado") {
    $actual = '<b>'.$lang["flat-single-rent-available"].'</b> <span class="ft-thinest">/ '.$lang["flat-single-rent-unavailable"].'</span>';
} else if ($flat["elado_statusz"] == 1 && $flatType == "elado") {
    $actual = '<span class="ft-thinest">'.$lang["flat-single-sell-available"].' /</span> <b>'.$lang["flat-single-sell-unavailable"].'</b>';
} else {
    $actual = '<span class="ft-thinest">'.$lang["flat-single-rent-available"].' /</span> <b>'.$lang["flat-single-rent-unavailable"].'</b>';
}
$price = ($flat["elado_kiado"] == "kiado") ? formatPrice($flat["ar_berles"])."Ft / ".$lang["general-month"] : formatPrice($flat["ar_vetel"]);
$lift = ($flat["lift"]) ? $lang["general-there-is"] : $lang["general-there-isnt"];
$description = ($language == "hu") ? $flat["leiras"] : $flat["leiras_en"];
$location = ($language == "hu") ? $flat["kornyek"] : $flat["kornyek_en"];

// echo "<br><br><br><br><br>";
// echo $sqlFlats;
// echo "<pre>";
// print_r($flat);
// echo "</pre>";

//Check the images
$imagesTmp = scandir("img/flats");

foreach ($imagesTmp as $key => $value) {
    $img = array();

    if (strlen($value) > 3 && strpos($value, formatLink($flat["cim"]."_".$flatId."_galery")) !== false && strpos($value, "_respo") !== false) {
        $img["respo"] = $value;
        $img["high_res"] = str_replace("_respo", "_high_res", $value);

        $galeryImages[] = $img;
    }
    $_flatImage = "";

    foreach ($imagesTmp as $key => $value) {
        //echo $value." == ".formatLink($flat["cim"]."_".$flatId)."_high_res<br>";
        if (strlen($value) > 3 && strpos($value, formatLink($flat["cim"]."_".$flatId)."_high_res") !== false && strpos($value, "_galery") == false) {
            $_flatImage = $value;
        }
    }

    if (is_file("img/flats/".$_flatImage)) {
        $flatImage = "img/flats/".$_flatImage."?".time();
    } else {
        $flatImage = 'img/nincs_kep.jpg';
    }
}
//Check the picture profile picture of the assistant
$imagesTmp = scandir("img/assistants");

foreach ($imagesTmp as $key => $value) {
    if (strlen($value) > 3 && strpos($value, formatLink($flat["nev"]."-".$flat["id"])) !== false) {
        $assistantImage = "assistants/".$value;
        break;
    } else {
        $assistantImage = "nincs_kep.jpg";
    }
}

// print_r($galeryImages);

?>
    <script src="js/elementInViewport.js"></script>
    <script type="text/javascript">
        $(document).ready(function() {
            var flatDesc = $("#flat-desc");
            var flatInfoList = $("#flat-info-list");
            var flatInfoEstateAgent = $("#flat-info-estate-agent");
            var flatLocation = $("#flat-location");
            var estateAgent = $("#estate-agent");

            $('#imageGallery').lightSlider({
                gallery:true,
                loop:true,
                pauseOnHover: true,
                easing: 'cubic-bezier(0.25, 0, 0.25, 1)',
                speed: 600,
                auto: true,
                pause: 5000,
                item: 1,
                thumbItem:5,
                slideMargin:0,
                enableDrag: false,
                currentPagerPosition:'middle'
                // onSliderLoad: function(el) {
                //  el.lightGallery({
                //      selector: '#imageGallery .lslide'
                //  });
                // }
            });

            $(window).scroll(function() {
                checkAnimation(flatDesc);
                checkAnimation(flatInfoList);
                checkAnimation(flatInfoEstateAgent);
                checkAnimation(flatLocation);
                checkAnimation(estateAgent);
            });

            // SnazzyMap
            var latitude = '<?php echo $flat["latitude"] ?>';
            var longtitude = '<?php echo $flat["longtitude"] ?>'; 
            initMap(latitude, longtitude);

            $("#estate-agent .button-green").on("click", function() {
                $("#estate-agent .contact-form").slideToggle("slow");
            });
        });
    </script>
    <div id="flat-single" class="container-fluid page">
        <div class="row">
            <div class="parallax-bg" style="background-image: url('<?php echo $flatImage?>'); margin-top: 0;">
                <div class="gradient-diamond"></div>
            </div>
            <div class="container">
                <div class="row">
                    <div id="flat-desc" class="col-sm-12 anim-1s">
                        <h1 class="ft-green text-center mar-top-50"><?php echo $district.", ".$flat["cim"] ?></h1>
                        <h3 class="ft-green text-center"><?php echo $actual ?></h3>
<!--                        <h2 class="ft-green text-center" style="margin-top: 0px;"><?php echo $district ?></h2> -->
                        <div class="row" style="position: relative; overflow: hidden;">
                            <div id="flat-info-list" class="col-sm-6 text-center mar-top-50 anim-1s">
                                <ul>
                                    <li><?php echo $lang["flat-single-price"].": " ?><span class="ft-green"><?php echo $price ?></span></li>
                                    <li><?php echo $lang["flat-single-size"].": " ?><span class="ft-green"><?php echo $flat["meret_nm"] ?>m<sup>2</sup> </span></li>
                                    <li><?php echo $lang["flat-single-rooms"].": " ?><span class="ft-green"><?php echo $flat["szobaszam"] ?></span></li>
                                    <li><?php echo $lang["flat-single-level"].": " ?><span class="ft-green"><?php echo $flat["emelet"] ?></span></li>
                                </ul>
                            </div>

                            <div id="flat-info-estate-agent" class="col-sm-6 mar-top-50 anim-1s">
                                <div class="row">
                                    <div class="col-sm-6 text-right">
                                        <img class="img-responsive" src="img/nincs_kep.jpg">
                                    </div>
                                    <div class="col-sm-6 text-left">
                                        <h2 class="ft-green" style="margin-top: 8px;"><?php echo $flat["nev"] ?></h2>
                                        <h3 class="ft-green">
                                            <?php echo $flat["pozicio"] ?>
                                        </h3>
            <!--                                <h4 class="ft-green">Budapest</h4> -->
                                        <br>
                                        <h4 class="ft-gray"><?php echo $flat["telefonszam"] ?></h4>
                                        <h4 class="ft-gray"><a href="mailto:<?php echo $flat["email"] ?>"><?php echo $flat["email"] ?></a></h4>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div id="flat-desc-txt" class="row">
                            <div class="col-sm-12 text-center mar-top-50">
                                <p style="font-size: 1.2em;">
                                    <?php echo $description ?>
                                </p>
                            </div>
                        </div>
                        <div class="row mar-top-50 flat-info">
                            <div class="col-sm-12">
                                <?php if (isset($galeryImages)): ?>
                                <ul id="imageGallery">
                                    <?php foreach ($galeryImages as $img): ?>
                                    <li data-thumb="img/flats/<?php echo $img["respo"] ?>" data-src="img/flats/<?php echo $img["high_res"] ?>">
                                        <img class="img-responsive" src="img/flats/<?php echo $img["high_res"] ?>" />
                                    </li>
                                    <?php endforeach ?>
                                </ul>
                                <?php endif ?>
                            </div>
                        </div>

                        <div id="flat-location" class="row mar-top-50">
                            <h2 class="ft-green text-center" style="margin-top: 0px;"><span class="border-bot-green"><?php echo $lang["flat-single-map-location"] ?></span></h2>

                            <div id="map" class="col-sm-12 mar-top-50"></div>

                            <div class="col-sm-12 text-center mar-top-50">
                                <?php if (!empty($location)): ?>
                                <h2 class="ft-green text-center"><span class="border-bot-green"><?php echo $lang["flat-single-location"] ?></span></h2>
                                <p class="mar-top-50" style="font-size: 1.2em;">
                                    <?php echo $location ?>
                                </p>    
                                <?php endif ?>
                            </div>

                        </div>
                        <div id="estate-agent" class="row mar-top-50 anim-1s">
                            <h2 class="ft-green text-center"><span class="border-bot-green"><?php echo $lang["general-more-info"] ?></span></h2>

                            <div class="col-sm-3 col-sm-offset-3 mar-top-50">
                                <img class="img-responsive" src="img/<?php echo $assistantImage."?".time(); ?>">
                            </div>

                            <div class="col-sm-4 mar-top-50">
                                <h2 class="ft-green"><?php echo $flat["nev"] ?></h2>
                                <h3 class="ft-green">
                                    <?php echo $flat["pozicio"] ?>
                                </h3>
<!--                                <h4 class="ft-green">Budapest</h4> -->
                                <br>
                                <h4 class="ft-gray"><?php echo $flat["telefonszam"] ?></h4>
                                <h4 class="ft-gray"><a href="mailto:<?php echo $flat["email"] ?>"><?php echo $flat["email"] ?></a></h4>
                            </div>

                            <div class="col-sm-12 text-center mar-top-50">
                                <input class="button-green anim-03s" type="button" name="" value="<?php echo $lang["flat-single-contact"] ?>" style="font-size: 1.5em; padding: 15px 25px;">
                            </div>

                            <div class="col-sm-12 contact-form">    
<!--                                <h2 class="ft-green text-center"><span class="border-bot-green">Vedd fel velünk a kapcsolatot!</span></h2> -->
                                <form class="mar-top-50" name="contactform" method="post" action="send_email_form.php" enctype="multipart/form-data">
                                    <input type="text" name="name" class="ft-green" placeholder="<?php echo $lang['kapcsolat-nev'] ?>">
                                    <br><br>
                                    <input type="text" name="from" class="email ft-green" placeholder="<?php echo $lang['kapcsolat-email'] ?>">
                                    <br><br>
                                    <input type="text" name="subject" class="ft-green" placeholder="<?php echo $lang['kapcsolat-targy'] ?>" value="Érdeklődés a(z) <?php echo $flat["cim"]." ".$flat["meret_nm"]."m2-es" ?> lakással kapcsolatban">
                                    <br><br>
                                    <textarea name="message" class="inp-textarea ft-green" placeholder="<?php echo $lang['kapcsolat-uzenet'] ?>" rows="10">
Kedves <?php echo $flat["nev"] ?>!

A következő kérdésem lenne a lakással kapcsolatban:

</textarea>
                                    <br><br>
                                    <input type="submit" name="submit" value="<?php echo $lang['kapcsolat-kuldes'] ?>" class="submit">
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

<?php include("footer.php"); ?>

Upvotes: 0

Views: 71

Answers (1)

Mark Rabey
Mark Rabey

Reputation: 1405

It looks like it's the page loading from the server that is taking so long. Whatever is looking up that ID on the other end seems to be what's slow. I'd take a look at overall server speed, but also make sure you have indexes on your database, that could speed things up as well.

Upvotes: 1

Related Questions