• User

    Preload o caricamento asincrono in un include php

    Ciao,
    io ho una pagina php che mi chiama il seguente include

    <?php include_once("latest.inc.php"); ?>

    però questo mi rallenta di 6 secondi la visualizzazione della pagina anzi per 6 secondi proprio non carica nulla.

    ho scoperto che a rallentare la pagina è proprio quell'include, quindi chiedo a qualche guru, come posso fare a fare un preload o un caricamento asincrono in modo che mi venga mostrato il tutto e soltanto successivamente inizi a caricare latest.inc.php.

    Attendo qualche buon samaritano che mi vorrà aiutare
    GRazie
    Manuel:quote:

    il codice è xzero e il sito è trovacuccioli.com


  • User Attivo

    Più che altro potresti installare un meccanismo di cache o capire perché quel file rallenta l'esecuzione della pagina: hai provato a capire se ci sono riferimenti esterni all'interno di quel file?


  • Super User

    Ciao, crea un DIV assegnandogli un ID univoco. Poi via AJAX carichi quel file e lo metti nel DIV contenitore.

    M.


  • User

    questo è il codice completo della pagina main e sotto la pagina include... non sono una cime, quindi ogni aiuto è ben gradito
    MAIN

    <?php

    /*--------------------------------------------------+
    | X-ZERO COMMUNITY CLASSIFIEDS SCRIPT |
    +===================================================+
    | File: main.php |
    | Homepage with the directory |

    require_once("initvars.inc.php");
    require_once("config.inc.php");

    ?>

    <?php //include("welcome.inc.php"); ?>

    <div class="categorytablewrapper">
    <table id="categories" class="categories">
    <tbody><tr>

    <?php

    // Create main directory

    if($dir_sort)
    {
    $sortcatsql = "ORDER BY catname";
    $sortsubcatsql = "ORDER BY subcatname";
    }
    else
    {
    $sortcatsql = "ORDER BY pos";
    $sortsubcatsql = "ORDER BY scat.pos";
    }

    // First get ads per cat and subcat
    $subcatadcounts = array();
    $catadcounts = array();
    $sql = "SELECT scat.subcatid, scat.catid, COUNT(*) as adcnt
    FROM $t_ads a
    INNER JOIN $t_subcats scat ON scat.subcatid = a.subcatid AND ($visibility_condn)
    INNER JOIN $t_cats cat ON cat.catid = scat.catid
    INNER JOIN $t_cities ct ON a.cityid = ct.cityid
    WHERE scat.enabled = '1'
    $loc_condn
    GROUP BY a.subcatid";

    $res = mysql_query($sql) or die(mysql_error().$sql);

    while($row=mysql_fetch_array($res))
    {
    $subcatadcounts[$row['subcatid']] = $row['adcnt'];
    $catadcounts[$row['catid']] += $row['adcnt'];
    }

    // Categories
    $sql = "SELECT catid, catname AS catname FROM $t_cats WHERE enabled = '1' $sortcatsql";
    $rescats = mysql_query($sql) or die(mysql_error());
    $catcount = chiocciolamysql_num_rows($rescats);

    $percol_short = floor($catcount/$dir_cols);
    $percol_long = $percol_short+1;
    $longcols = $catcount%$dir_cols;

    $i = 0;
    $j = 0;
    $col = 0;
    $thiscolcats = 0;

    while($rowcat=mysql_fetch_array($rescats))
    {
    if ($j >= $thiscolcats)
    {
    $col++;
    $thiscolcats = ($col > $longcols) ? $percol_short : $percol_long;
    $j = 0;

    	echo "<td id=\"column_$col\" valign=\"top\" width=\"$cell_width%\">";
    }
    
    
    $i++;
    $j++;
    
    
    $catname_inurl = RemoveBadURLChars($rowcat['catname']);
    if($sef_urls) $catlink = "{$vbasedir}$xcityid/posts/$rowcat[catid]_{$catname_inurl}/0/";
    else $catlink = "?view=ads&catid=$rowcat[catid]&cityid=$xcityid&lang=$xlang";
    
    
    $adcount = 0+$catadcounts[$rowcat['catid']];
    

    ?>

    <div class="category">
    	<div class="catbuffer">
    		<?php //$category_icon = file_exists("images/category/{$rowcat[catid]}.gif") ? "images/category/{$rowcat[catid]}.gif" : "images/category.gif"; ?>
    		<div class="catimage cat<?php echo $rowcat[catid]; ?>"><!--<img src="<?php //echo $category_icon; ?>" border="0" align="absmiddle">--></div>
    		<div class="caturl"><a class="maj" href="<?php echo $catlink; ?>"><?php echo $rowcat['catname']; ?></a>
    		<?php if($show_cat_adcount) { ?><span class="count">(<?php echo $adcount; ?>)</span><?php } ?></div>
    	</div>
    <?php if($show_subcat) { ?>	
    <div class="catsublinks">
    

    <?php

    $sql = "SELECT scat.subcatid, scat.subcatname AS subcatname
    FROM $t_subcats scat
    WHERE scat.catid = $rowcat[catid]
    	AND scat.enabled = '1'
    $sortsubcatsql";
    
    
    $ressubcats = mysql_query($sql) or die(mysql_error()."<br>$sql");
    
    
    while ($rowsubcat = mysql_fetch_array($ressubcats))
    {
    	$adcount = 0+$subcatadcounts[$rowsubcat['subcatid']];
    
    
    	if($sef_urls) $subcat_url = "{$vbasedir}$xcityid/posts/$rowcat[catid]_{$catname_inurl}/$rowsubcat[subcatid]_". RemoveBadURLChars($rowsubcat['subcatname'])."/";
    	else $subcat_url = "?view=ads&catid=$rowcat[catid]&subcatid=$rowsubcat[subcatid]&cityid=$xcityid&lang=$xlang";
    

    ?>
    <a href="<?php echo $subcat_url; ?>"><?php echo $rowsubcat['subcatname']; ?></a>
    <?php if($show_subcat_adcount) { ?><span class="count">(<?php echo $adcount; ?>)</span><?php } ?>
    <br />

    <?php

    }
    

    ?>
    </div>
    <?php } ?>
    </div>

    <?php

    if($j==$thiscolcats || $i==$catcount) echo "</td>";
    

    }

    ?>

    </tr></tbody></table>
    </div>

    <?php include_once("latest_featured.inc.php"); ?>

    <?php include_once("upcoming_featured_events.inc.php"); ?>

    <?php include_once("latest.inc.php"); ?>

    <?php include_once("upcoming_events.inc.php"); ?>


  • User

    ed ecco la pagina LATEST INC

    <?php

    /-----------------------------------------------+
    | X-ZERO COMMUNITY CLASSIFIEDS |
    +================================================+
    | Copyright ? 2005 Davis 'X-ZERO' John |
    | Scriptlance ID: davisx0 |
    | Email: |
    | |
    | // Sat, Dec 17, 2005 |
    +-----------------------------------------------
    /

    require_once("initvars.inc.php");
    require_once("config.inc.php");

    ?>
    <?php
    if($latestads_count)
    {
    ?>

    <!-- Begin Version 5.0 -->
    <div class="latestposts">
    <!-- End Version 5.0 -->
    <div class="head"><?php echo $lang['LATEST_ADS']; ?></div>

    <!-- Begin Version 5.0 -->
    <table border="0" cellspacing="0" cellpadding="0" class="postlisting" width="100%">
    <!-- End Version 5.0 -->

    <?php
    $sql = "SELECT a.adid, a.adtitle, a.cityid, a.subcatid, ct.cityname, feat.adid AS isfeat,
    p.picfile AS picfile, scat.subcatname, scat.catid, cat.catname
    FROM $t_ads a
    INNER JOIN $t_cities ct ON a.cityid = ct.cityid
    INNER JOIN $t_subcats scat ON a.subcatid = scat.subcatid
    INNER JOIN $t_cats cat ON scat.catid = cat.catid
    LEFT OUTER JOIN $t_featured feat ON a.adid = feat.adid AND feat.adtype = 'A' AND feat.featuredtill >= NOW()
    LEFT OUTER JOIN $t_adpics p ON a.adid = p.adid AND p.isevent = '0'
    WHERE $visibility_condn
    $loc_condn
    GROUP BY a.adid
    ORDER BY a.createdon DESC
    LIMIT $latestads_count";
    $res_latest = mysql_query($sql) or die($sql.mysql_error());

    $css_first = "_first";
    while($row = mysql_fetch_array($res_latest))
    {
    	/* Begin Version 5.0 */
    	$url = buildURL("showad", array($xcityid, $row['catid'], $row['catname'], 
    	    $row['subcatid'], $row['subcatname'], $row['adid'], $row['adtitle']));
    	/* End Version 5.0 */
    

    ?>

    	<?php 
    	if($row['isfeat'])
    	{
    		//$feat_class = "class=\"featured\"";
    		$feat_img = "<img src=\"images/featured.gif\" align=\"absmiddle\">";
    	} 
    	else 
    	{ 
    		//$feat_class = "";
    		$feat_img = "";
    	}
    
    
    	if($row['picfile']) 
    	{
    		$picfile = $row['picfile'];
    		$imgsize = GetThumbnailSize("{$datadir[adpics]}/{$picfile}", $tinythumb_max_width, $tinythumb_max_height);
    	}
    	else 
    	{
    		$picfile = "";
    	}
    	?>
    
    
    	<tr>
    		<td width="15">
    		<img src="images/bullet.gif" align="absmiddle">
    		</td>
    		
    		<td>
    		<b><a href="<?php echo $url; ?>" <?php echo $feat_class; ?>><?php echo $row['adtitle']; ?></a></b> 
    		<?php if(0&&$row['picfile']) { ?><img src="images/adwithpic.gif" align="absmiddle"><?php } ?>
    		<?php echo $feat_img; ?><br>
    
    
    
    
    		<span class="adcat">
    		
    		
    		
    		<?php echo "$row[catname] $path_sep $row[subcatname]"; ?>
    		
    		
    		
    		<?php 
    		$loc = "";
    		if($row['area']) $loc = $row['area'];
    		if($xcityid < 0) $loc .= ($loc ? ", " : "") . $row['cityname'];
    		if($loc) echo "<br>$loc";
    		?>			
    		
    		</span>
    
    
    		
    		
    		</td>
    
    
    		<td  align="right" width="<?php echo $tinythumb_max_width; ?>">
    		<?php if($picfile) { ?>
    		<a href="<?php echo $url; ?>"><img src="images/grey.gif" data-original="<?php echo "{$datadir[adpics]}/thumbs/tn_{$picfile}"; ?>" border="0" width="<?php echo $imgsize[0]; ?>" height="<?php echo $imgsize[1]; ?>" style="border:1px solid black"></a>
    		<?php } ?>
    		</td>
    		
    	</tr>
    

    <?php
    $css_first = "";
    }
    ?>

    </table>
    </div>

    <?php
    }
    ?>