Incarcare inceata a paginii principale
Scris: Mar Feb 27, 2018
Salut,
Am o baza de date structurata astfel:
iar codul php este:
Baza de date are aproximativ 3.200.000 randuri cu o marime de 3.3 GB.Atunci cand incarc pagina index dureaza intre 100 si 900 secunde pentru a termina procesul (la fel cand folosesc si butoanele pentru urmatoarea pagina sau anterioara), cu toate ca am setat sa afiseze doar 50 rezultate/pagina. Ce as putea sa schimb in baza de date pentru o incarcare rezonabila? In codul php nu am vazut nimic ce ar putea fi schimbat.Varianta la care m-am gandit ar fi sa sterg toate thumbnails din baza de date, iar apoi sa scriu un cod java care sa extraga un thumbnail din video.Problema este ca nu sunt sigur daca acesta varianta ar inbunatati viteza de incarcare, iar a doua problema este ca eu nu detin nici un fisier video ci doar url-uri catre video.
PS. Inca lucrez pe 127.0.0.1 (localhost). nu gasesc nici un serviciu de gazduire gratis care sa imi urce toata baza de date.
Un pic de ajutor va rog
Am o baza de date structurata astfel:
Cod: SelectaĊ£i tot
id url embed_url title duration date_added thumb1 thumb2 ... thumb10 categories
1 link1 embed_link title1 values in seconds yyyy-mm-dd link_thumb1 link_thumb1 link_thumb1 category1,category2
Cod: SelectaĊ£i tot
<?php
$my_timer = microtime();
$time_parts = explode(' ', $my_timer);
$time_right_now = $time_parts[1] + $time_parts[0];
$starting_time = $time_right_now;
include 'config.php';
define('CSSPATH', '');
$cssItem = 'styles.css';
?>
<!DOCTYPE html>
<html>
<head>
<title><?php echo $title; ?></title>
<link rel="stylesheet" type="text/css" href="<?php echo (CSSPATH . "$cssItem"); ?>">
</head>
<body>
<div class="header">
<div class="container">
<div class="logo">
<h1><a href="#"><span style="color:#840607;">NU</span><span class="style4">Conteaza<sup>Beta</sup></span></a></h1>
</div>
</div>
</div>
<!--- <div class="left">
<p>menu</p>
<p>menu</p><p>menu</p>
<p>menu</p>
<p>menu</p><p>u</p>
</div>--->
<div class="container">
<div class="content">
<?php
$conn = mysql_connect($host, $utilizator, $parola);
if (!$conn) {
echo 'Conectare nereusita la MySQL';
exit;
}
if (!mysql_select_db($numebd, $conn)) {
echo 'Baza de date nu a putut fi selectata deoarece : '. mysql_error();
exit;
}
$sql = "SET NAMES 'utf8'";
mysql_query($sql, $conn);
$sql = "SELECT COUNT(*) FROM `nuconteaza`";
$result = mysql_query($sql, $conn) or trigger_error(E_USER_ERROR);
$r = mysql_fetch_row($result);
$numrows = $r[0];
$rowsperpage = 50;
$totalpages = ceil($numrows / $rowsperpage);
if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
$currentpage = (int) $_GET['currentpage'];
} else {
$currentpage = 1;
}
if ($currentpage > $totalpages) {
$currentpage = $totalpages;
}
if ($currentpage < 1) {
$currentpage = 1;
}
$offset = ($currentpage - 1) * $rowsperpage;
$sql = "SELECT id, url, thumb1 FROM `nuconteaza` ORDER BY date_added DESC LIMIT $offset, $rowsperpage";
$result = mysql_query($sql, $conn) or trigger_error(E_USER_ERROR);
$re_out ='';
$i =0;
while ($list = mysql_fetch_assoc($result)) {
$id[] = $list['id'];
$url[] = $list['url'];
//$embed_url[] = $list['embed_url'];
//$description[] = $list['description'];
//$duration[] = $list['duration'];
//$date_added[] = $list['date_added'];
$thumb1[] = $list['thumb1'];
//$thumb2[] = $list['thumb2'];
//$thumb3[] = $list['thumb3'];
//$thumb4[] = $list['thumb4'];
//$thumb5[] = $list['thumb5'];
//$thumb6[] = $list['thumb6'];
//$thumb7[] = $list['thumb7'];
//$thumb8[] = $list['thumb8'];
//$thumb9[] = $list['thumb9'];
//$thumb10[] = $list['thumb10'];
//$categories[] = $list['categories'];
//$views_count[] = $list['views_count'];
$re_out .='<a href="'.$list["url"].'" target="_blank" class="padre"><img src="'.$list["thumb1"].'" style="width:160px;height:120px" >';
$i++;
if(($i%5)==0) $re_out .='<br>';
}
mysql_close();
echo $re_out ;
$range = 3;
if ($currentpage > 0) {
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> ";
$prevpage = $currentpage - 1;
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> ";
}
for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
if (($x > 0) && ($x <= $totalpages)) {
if ($x == $currentpage) {
echo " [<b>$x</b>] ";
} else {
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> ";
}
}
}
if ($currentpage != $totalpages) {
$nextpage = $currentpage + 1;
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> ";
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> ";
}
$my_timer = microtime();
$time_parts = explode(' ', $my_timer);
$time_right_now = $time_parts[1] + $time_parts[0];
$finishing_time = $time_right_now;
$total_time_in_secs = round(($finishing_time - $starting_time), 4);
echo 'Page generated in '.$total_time_in_secs.' seconds.';
?>
</div>
<div class="footer">
</div>
</div>
</body>
</html>
PS. Inca lucrez pe 127.0.0.1 (localhost). nu gasesc nici un serviciu de gazduire gratis care sa imi urce toata baza de date.
Un pic de ajutor va rog