...

View Full Version : Very Slow loading time !!!!!



Peuplarchie
02-24-2008, 05:16 AM
Good day to you all,
I am working on ascript for long time but a big problem that I'm not able to resolve is the loading time,is someone can help me?

here is the code :




<?php

$image_counter = -1;
$row_counter = 0;
$cell_counter = 0;
$i=0;
$show=array('.jpg','.JPG','.gif','.GIF');

$val= $_GET['folder'];
$val1 = $_GET['folder'];
$val0 = $val1;
$val.="/";

$path = "$val";
$path2 = str_replace("Pic-S", "Pic-B", $val);
$dirshort = substr($val,20);
$dirshort0 = $val1;

$comicon = "http://test.com/comment.txt";
$fh1 = fopen($comicon, 'r');
$outputt1 = fgets($fh1);
$output1 = str_replace("../..", "http://test.com", $outputt1 );
fclose($fh1);



$dir_handle = @opendir($path) or die("Unable to open $path");
$image_table = "\n<tr><td bgcolor=\"#cccccc\" align=\"center\" colspan=\"3\" width=\"100%\"><table valign=\"top\" align=\"center\" width=\"100%\" border=\"0\" cellspacing=\"0\">\n";
while (false !== ($file = readdir($dir_handle))) {

if(in_array(substr($file,-4,4),$show)){
if(!(($image_counter + 1) % 3)){
$row_counter++;
}


$newpath0 = substr($file,0,-4);
$newpath00 = substr($file,0,-4);

$image_table_arr[$i] .=(($image_counter + 1) % 3)? "" : "</tr>\n<tr><td><br></td></tr><tr valign=\"top\">";
$image_table_arr[$i] .= "\n<td valign=\"top\" width=\"240\"><table width=\"240\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\" align=\"center\">\n";
$image_table_arr[$i] .= "\n<tr><td valign=\"top\" bgcolor=\"#ffff00\" width=\"240\"><table width=\"240\" border=\"0\" cellpadding=\"1\" cellspacing=\"0\" align=\"center\">\n";
$image_table_arr[$i] .= "\n<tr><td valign=\"top\" bgcolor=\"#003366\" width=\"240\"><table width=\"240\" border=\"0\" cellpadding=\"1\" cellspacing=\"0\" align=\"center\">\n";
$image_table_arr[$i] .= "\n<tr><td bgcolor=\"#000033\" align=\"center\"width=\"240\"><b>$newpath0</b></td></tr>\n";
$image_table_arr[$i] .= "\n<tr><td bgcolor=\"#000000\" width=\"240\"><a href='http://test.com/Art/$path2$file' target='_blank' rel=\"thumbnail\"><img src=\"http://test.com/Art/$path$file\" width=\"240\" border=\"0\"></a></td></tr>\n";
$image_table_arr[$i] .= "\n<tr><td bgcolor=\"#000033\" align=\"center\" width=\"240\"><IMG SRC=\"http://test.com/Art/minus.gif\" CLASS=\"showstate\" ONCLICK=\"expandcontent(this, 'sc".$newpath0."')\" align=\"right\"><b>Information</b></td></tr>\n";
$image_table_arr[$i] .= "\n</table>\n";
$image_table_arr[$i] .= "\n<div id=\"sc".$newpath0."\" class=\"switchcontent\" width=\"240\">\n";
$image_table_arr[$i] .= "\n<table border=0 align=center cellspacing=0 cellpading=0 width=\"240\">\n";
$image_table_arr[$i] .= "\n<tr><td bgcolor=\"#ffffff\" align=\"left\" class=\"black0\" width=\"240\"><b class=\"black0\" width=\"240\">Description :<br></b><script type=\"text/javascript\">ajaxinclude(\"http://test.com/Art/Pictures/Pics/Commentaires/$newpath0.txt\")</script></td></tr>\n";
$image_table_arr[$i] .= "\n<tr><td bgcolor=\"#ffffff\" align=\"left\" class=\"black0\" width=\"240\"><br></td></tr>\n";
$image_table_arr[$i] .= "\n<tr><td valign=\"top\" bgcolor=\"#ffffff\" width=\"240\"><table width=\"240\" border=\"0\" cellpadding=\"1\" cellspacing=\"0\" align=\"center\">\n";
$image_table_arr[$i] .= "<tr><td bgcolor=\"#ffffff\" align=\"left\" width=\"240\" valign=\"top\"><a href=\"http://test.com/Art/rater0.php?var1=$newpath0&var00=$path$file\" target=\"autre\" title=\"Rate it! - Noter la !\" alt=\"Rate it!\" class=\"black000\"><script type=\"text/javascript\">ajaxinclude(\"http://test.com/Art/rater1.php?var1=$newpath0&var00=$path$file\")</script></a></td>";
$image_table_arr[$i] .= "\n<td bgcolor=\"#ffffff\" align=\"center\" class=\"black0\" width=\"240\" colspan=\"2\"><script type=\"text/javascript\">ajaxinclude(\"http://test.com/Art/Pictures/Pics/Prix/$newpath0.txt\")</script><script type=\"text/javascript\">ajaxinclude(\"http://test.com/Art/Pictures/Pics/Vente/$newpath0.txt\")</script></td></tr>\n";
$image_table_arr[$i] .= "\n</table>\n";
$image_table_arr[$i] .= "\n<tr><td valign=\"top\" bgcolor=\"#ffffff\" width=\"240\"><table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" align=\"center\">\n";
$image_table_arr[$i] .= "\n<tr><td bgcolor=\"#ffffff\" align=\"center\" width=\"240\"><a href=\"http://test.com/commentaires.php?var001=$newpath0&var002=$path$file\" target=\"autre\" title=\"Add comments - Ajout de commentaires.\" alt=\"Add comments - Ajout de commentaires\" class=\"white000\"><img src=\"".$output1."\" border=\"0\"></a></td>";
$image_table_arr[$i] .= "</td></tr>\n";
$image_table_arr[$i] .= "\n</table>\n";
$image_table_arr[$i] .= "\n</div>\n";
$image_table_arr[$i] .= "\n</table>\n";
$image_table_arr[$i] .= "\n</table>\n";
$image_table_arr[$i] .= "\n</table></td>\n\n\n";
$i++;
++$image_counter;
++$cell_counter;
}
}
$no_of_images = count($image_table_arr);
$colspan= ($row_counter * 3) - $cell_counter;



$to = 9;
if(isset($_GET['from']))
$from = $_GET['from'];
else
$from = -$no_of_images;
$from000 = substr($from, -1);

error_reporting(E_ALL);
ini_set('display_errors','Off');
$path4 = substr($path,24);


$i1 = $i+1;
$image_table_arr= array_slice($image_table_arr, $from, $to) or exit("<center><b> - No photo in this folder : ($path4) for now. <br><br>- Pas de photo dans ce dossier : ($path4) pour le moment.<br><br></b></center></table></table></div><!--content goes here --><b class=\"rbottom\"><b class=\"r4\"></b> <b class=\"r3\"></b> <b class=\"r2\"></b> <b class=\"r1\"></b></b></div></center>");
$image_table .= "\n<tr><td valign=\"top\" width=\"100%\" colspan=\"3\" ><table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" align=\"center\">\n";
$image_table .= "\n<tr><td bgcolor=\"#000033\" class=\"white00\" width=\"680\" align=\"left\"><b class=\"white00\">Photos in - Photos dans :</b> $dirshort ";
$image_table .= "\n</td>";
$image_table .= "\n <td bgcolor=\"#000033\" align=\"right\" width=\"100\"><div class=\"Slideshow\"><a href=\"javascript:void(viewer.show(0))\">Slideshow</a></div></td></tr>\n";
$image_table .= "\n</td></tr>\n";
$image_table .= "\n<tr><td bgcolor=\"#cccccc\" class=\" white00\" align=\"right\" colspan=\"3\">\n";
$image_table .= "<script type=\"text/javascript\">ajaxinclude(\"http://test.com/change_shoppingcart_button.txt\")</script>";
$image_table .= "\n</td></tr>\n";
$image_table .= "\n<tr>\n";
$image_table .= "\n</table>\n";



$image_table .= "\n<tr><td bgcolor=\"#cccccc\" align=\"center\" class=\"black002\" colspan=\"3\" width=\"100%\"><b class='black002'>Page : </b>";
$paginate = ceil($no_of_images/$to);




for ($i=0;$i<$paginate;$i++)
{
$from_val = $no_of_images-($to*$i);
$image_table .= "<a href='".$_SERVER['PHP_SELF']."?folder=$val1&from=-".$from_val."' >".($i+1)."</a>&nbsp;-&nbsp;";

}
echo "</td></tr>";
echo $image_table;
echo implode("",$image_table_arr);
$image_table1 .= "</tr>\n\n";
$image_table1 .="<tr><td bgcolor=\"#cccccc\" align=\"center\" class=\"black002\" colspan=\"3\" width=\"780\"><br><b class='black002'>Page : </b>";
for ($i=0;$i<$paginate;$i++)
{
$from_val = $no_of_images-($to*$i);

$image_table1 .= "<a href='".$_SERVER['PHP_SELF']."?folder=$val1&from=-".$from_val."' >".($i+1)."</a>&nbsp;-&nbsp;";

}

echo "<tr><td bgcolor=\"#cccccc\" valign=\"top\"><br><br></td></tr></table>";
echo "$image_table1";


?>



Thanks !

Inigoesdr
02-24-2008, 12:25 PM
This is probably a big part of your problem. Why are you opening the comments file from an external site? If it's on the same server use the file path instead of the web path, and it will go a lot faster.

$comicon = "http://test.com/comment.txt";
$fh1 = fopen($comicon, 'r');
$outputt1 = fgets($fh1);
$output1 = str_replace("../..", "http://test.com", $outputt1 );
fclose($fh1);

Peuplarchie
02-25-2008, 11:32 PM
I have changed it now, still.

Inigoesdr
02-26-2008, 12:07 AM
How about some more info?
How long does it take to load? Use a timer if necessary.
Post your current code.
How big, and what is the txt file you're opening?
Is this the whole page you're viewing?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum