Jump to content

Script now takes 10X longer to load.


Archimedes

Recommended Posts

I was copying a php script that takes a string and runs it through 4 search engines prints out results. Before it only took 1 or 2 seconds but ever since I've copied the script, edited it, and run it, the original script now takes much much longer, like 40 or 50 seconds to load, and when it does there are no results shown for strings that had previously produced results. The script i've copied doesn't actually search, it just sends the string (along with some login info) to the 4 other search engines, and they give it back the results.

 

When I comment out two of the search engines MSNsearch and searchFeed it runs at it's normal speed (1 or 2 seconds) but with either one uncommented it takes the same time to load.

 

I've tried everything to undo all of the changes I've made to the original script but it still takes loads for a long time.

What could I have changed that would cause this? or maybe the script is the same as It was when it worked but my copied script messed something in the database. I've already checked on my subscriptions for these search engines and they seem functional. Please Help.

Link to comment
Share on other sites

The host is pretty crappy and it's even down at times but the slow loading has been going on for 5 days straight, which leads me to believe that I did something wrong.

 

 

here is the code of the script that I copied/edited and ran and may have not undone changes correctly.

 

when i comment out this line:

$msn_res_count = GetMSNResults($msn_results, $ss, $page*$rpp, $rpp+ceil

and this line:

$sf_res_count = GetSearchFeedResults($sfeed_results, $ss, $get_res, $rpp+ceil

it runs at normal speed but without results. This isn't the problem about no results though. When they are uncommented and the script runs it takes a long time and I don't get any results when i used to.

 

<?
/////////////////////////////////////
// PPC Search Engine.              //
// (c) eMade.com, 2002            //
//              //
/////////////////////////////////////
//                                 //
//  Main Search page               //
//                                 //
/////////////////////////////////////
echo "I should see this";
error_reporting(0);
require("path.php");
require($INC."config/config_main.php");
require($INC."config/config_main2.php");
require($INC."functions/functions_search.php");
mysql_connect ($DBHost, $DBLogin, $DBPassword);
mysql_selectdb ($DBName);
if(!isset($cmd)||$cmd==""||$cmd==0){
////////////////////////////////////////////////////////////////////////////////////////
//main page
	$location = "";
	$tmp = ReadTemplate($MAIN_MAIN_SCREEN);
	$bbb = array();
	$banners = GetRandomBanners2(3,0,$bbb,1);
                $i=count($banners);
                $k=$i-1;
                $ran=rand(0,$k);

                $vars = array("action"=>$MAIN_URL, "members_registration"=>"../members/registration.php", "members_login"=>"../members/", "banner1"=>GetBanner($banners[$ran])/*, "banner2"=>GetBanner($banners[1]), "banner3"=>GetBanner($banners[2])*/);
	$tmp = ParseTemplate($tmp, $vars);
	$content = "";
	if(!isset($menu)||$menu==0||$menu==""){
		$tmp = preg_replace("/<#topsearches#>/", TopSearches(), $tmp);
		$tmp = preg_replace("/<#categories#>/", GetCategories(), $tmp);

		$content = "";
	}else{
		ShowError("System error", "incorrect menu item", $ADMIN_URL);
	}
	$tmp = preg_replace("/<#content#>/", $content, $tmp);
	print $tmp;
//end of main  page
////////////////////////////////////////////////////////////////////////////////////////
}elseif($cmd==1){
////////////////////////////////////////////////////////////////////////////////////////
//Process search Query


	$location = "";
	if(isset($ss)&&$ss!=""&&!preg_match("/[%?_]/", $ss)&&AllowedKeywords($ss)){

		//check affiliates searches
		if(isset($member)&&$member!=0){
			if(dbSelectCount($TMembersAccounts, "STATUS=0")>0){
				session_unregister("amember");
				session_register("amember");
				$amember = $member;
				dbInsert($TASearches, "MemberID, ASDate", "'$member', CURDATE()");
			}
		}
		//end of check affiliates searches

		if(!isset($rpp)||$rpp==""||$rpp==0) $rpp = 10;
		if(!isset($hidesummary)||$hidesummary=="") $hidesummary = 0;
		if(!isset($page)||$page=="") $page = 0;

		$ppc_results = array();
		$categs_count = 0;
		$ppctype = PPCSearch($ss, $ppc_results, $categs_count);

		if(GetSettings("rpilot")!=0){
			$get_res = ceil($rpp/2)*$page;

			$rp_res_count = GetREVENUEResults($rpilot_results, $ss, $get_res, $rpp+ceil($rpp/2));

			if($rp_res_count==""){
				$rp_na = "";//"<br>no results were found on this page";
			}else{
				$rp_na = "";
			}
		}

		if(GetSettings("sfeed")!=0){
			$get_res = $page+1;

			$sf_res_count = GetSearchFeedResults($sfeed_results, $ss, $get_res, $rpp+ceil($rpp/2));
			if($sf_res_count==""){
				$sf_na = "";//"<br>no results were found on this page";
			}else{
				$sf_na = "";
			}
		}

		if(GetSettings("raging")!=0){
			$get_res = $rpp*$page;

			$raging_res_count = GetRAGINGResults($raging_results, $ss, $get_res, $rpp+ceil($rpp/2));
			if($raging_res_count==""){
				$rg_na = "";//"<br>no results were found on this page";
			}else{
				$rg_na = "";
			}
		}

		if(GetSettings("dmoz")!=0){

			$dmoz_res_count = GetDMOZResults($dmoz_results, $ss, $page*$rpp, $rpp+ceil($rpp/2));

			if($dmoz_res_count==""){
				$dmoz_na = "";//"<br>no results were found on this page";
			}else{
				$dmoz_na = "";
			}
		}
		if(GetSettings("msn")!=0){

			$msn_res_count = GetMSNResults($msn_results, $ss, $page*$rpp, $rpp+ceil($rpp/2));

			if($msn_res_count==""){
				$msn_na = "";//"<br>no results were found on this page";
			}else{
				$msn_na = "";
			}
                                 $m=count($msn_results);


		}
		$ppc_rescount = count($ppc_results) + $dmoz_res_count + $msn_res_count + $rp_res_count + $sf_res_count + $raging_res_count;
                        $p=count($ppc_results);

		$back = "";
		$tmp = ReadTemplate($MAIN_SRES_TMP);

		if($ppc_rescount>0){


			$content = PPCParseResults($ppctype, $ppc_results, $page, $rpp, $hidesummary, $ss);
			$total_pages = GetTotalPPCResPages($ppc_results, $rpp);
			$rg_pages = ceil($raging_res_count/$rpp);
			$sf_pages = ceil($sf_res_count/$rpp);
			$rp_pages = ceil($rp_res_count/$rpp);
			$dmoz_pages = ceil($dmoz_res_count/$rpp);
			$msn_pages = ceil($msn_res_count/$rpp);
			$total_pages+=$dmoz_pages+$msn_pages+$rp_pages+$sf_pages+$rg_pages;

			if($page>$total_pages) $page = $total_pages;

			if($total_pages>1){
				$pages_links = GetPagesLinks($page, $ppc_rescount, $rpp, "&cmd=1&ss=$ss&rpp=$rpp&hidesummary=$hidesummary");
			}else{
				$pages_links = "";
			}
			$ssumm = $ppc_rescount." site".($ppc_rescount>1?"s":"");
			if($ppctype==0){
				$ssumm.= " in ".$categs_count." categor".($categs_count>1?"ies":"y");
			}
		}else{
			$content = "<h2><br>No results were found</h2>";
			$pages_links = "";
			$ssumm = "";
		}
		$hdr = "<h3>Search results for «".$ss."»:</h3>";
		$banners = GetRandomBanners2(3, 1, $ppc_results, $ppctype);

                         $i=count($banners);

                         $k=$i-1;
                         $ran=rand(0,$k);

                         $vars = array("pages"=>$pages_links, "header"=>$hdr.$dmoz_na,"ss"=>$ss, "action"=>$MAIN_URL, "search_summary"=>$ssumm, "members_registration"=>"../members/registration.php", "members_login"=>"../members/", "banner1"=>GetBanner($banners[$ran])/*, "banner2"=>GetBanner($banners[1]), "banner3"=>GetBanner($banners[2])*/);
		$tmp = ParseTemplate($tmp, $vars);
		$tmp = preg_replace("/<#content#>/", $content, $tmp);
		print $tmp;
	}else{
		$location = $MAIN_URL;
	}
//End of Process Search Query
////////////////////////////////////////////////////////////////////////////////////////
}elseif($cmd==200){
	if(isset($id)&&$id!=""&&$id!=0){
		$rpp = 10;
		$ppc_results = array();
		PPCCategory($id, $ppc_results);
		$ppc_rescount = count($ppc_results);
		$back = "";
		$tmp = ReadTemplate($MAIN_SRES_TMP);
		if($ppc_rescount>0){
			$content = PPCParseResults(0, $ppc_results, $page, $rpp, $hidesummary);
			$total_pages = GetTotalPPCResPages($ppc_results, $rpp);
			if($total_pages>1){
				$pages_links = GetPagesLinks($page, $ppc_rescount, $rpp, "&cmd=200&id=$id");
				print $page_links;
			}else{
				$pages_links = "";
			}
			$ssumm = $ppc_rescount." site".($ppc_rescount>1?"s":"");
		}else{
			$content = "<h2><br>No results were found</h2>";
			$pages_links = "";
			$ssumm = "";
		}
		$cname = GetCategoryName($id);
		$hdr = "<h3>Browse category «".($cname!=""?$cname:"N/A")."»:</h3>";
		$bbb = array();
		$banners = GetRandomBanners2(3,0,$bbb,1);
                         $i=count($banners);
                         $k=$i-1;
                         $ran=rand(0,$k);

		$vars = array("pages"=>$pages_links, "ss"=>"", "header"=>$hdr, "action"=>$MAIN_URL, "search_summary"=>$ssumm, "members_registration"=>"../members/registration.php", "members_login"=>"../members/", "banner1"=>GetBanner($banners[$ran])/*, "banner2"=>GetBanner($banners[1]), "banner3"=>GetBanner($banners[2])*/);
		$tmp = ParseTemplate($tmp, $vars);
		$tmp = preg_replace("/<#content#>/", $content, $tmp);
	    	print $tmp;
	}else{
		$location = $MAIN_URL;
	}
}else{
	$location = $MAIN_URL;
}
mysql_close();
if($location!=""){
	header("Location: $location");
	exit;
}
?>


 

You can see the website here

http://www.buildbig.org/

any of the links at the bottom that say 'popular seraches' will run a search.

Link to comment
Share on other sites

A good way to debug the speed of your script is to use time() or a similar function in various parts of your script and outputting the time it takes for each block to execute. You can then localize the slowest parts of scripts by using more of these time measuring functions at even more exact locations inside of the offending code block.

Link to comment
Share on other sites

Can we see the 2 problematic functions. What it seems like is the request for the page is taking a long time. (If indeed you are grabbing data from an outside page)

 

Are you using CURL or? If not try cURL, it generally speeds up the time to retrieve a page.

Link to comment
Share on other sites

Every time I Echo anything inbetween the lines of this code to see where the long loading time starts it doesn't print until it's just about done. I put an echo statement at the very top of index.php which is the first script that the search link passes it's string to and it won't print out for a while. In fact I even have an echo statement at the top

 

echo "I should see this"; and it doesn' print that until along way into the loading. which doesn't make any sense because it should print and then have trouble somewhere else since nothing happens between the echo statement and the calling of it.

 

I'm certain that both of these weren't modified, these functions are the same as it was when it worked.

 

here is the MSN search

//MSN

function GetMSNResults(&$results, $ss, $start = 1, $num = 1){
	global $MSN_URL, $TRY_CONNECTIONS, $TRY_PAUSE;
	global $rpp;

	if($rpp==""||$rpp==0) $rpp = 10;
	$results = array(
							"0" => array(
							"title"=>"",
							"link"=>"",
							"summary"=>"",
							"category"=>""
						 )
	);


	if($start==0)
	  {
$link = $MSN_URL."&q=".urlencode($ss);

	  }
else
  {
    $r=13;
    $page=(($start/$rpp)-1)*15;
    $k=$r+$page;
    $msn=$k.".0(.)0...4.0.3.0.%26";
$MSN_URL="http://search.msn.com/results.aspx?";
//  $link=$MSN_URL."ps=ba%3d".$msn."co%3d15.4(0.1)3.200.2.5.10.3..%26pn%3d1%26rd%3d2%26&q=".urlencode($ss)."&ck_sc=1&ck_af=0";
//next 2 lines new
   $newnum = $start+1;
   $link=$MSN_URL."q=".urlencode($ss)."&first=$newnum&count=$rpp";


    $k=$k+15;
}

	$cc = 1;
	while(!($fh = @fopen($link, 'r'))){
		if($cc==$TRY_CONNECTIONS) break;
		$cc++;
		Pause($TRY_PAUSE);
	}
	if($fh){
		$buff = "";
		$tmp = "";
		$tmp_arr = array();
		while($buff = fread($fh, 256)){
			$tmp.=$buff;
		}
		fclose($fh);
		$sc = 0;


/*
		if(preg_match("/Results \d+-\d+ of about (\d+)/", $tmp, $m1)){
			$sc = $m1[1];
		}
*/
//new
		if(preg_match("/1-(.*)containing/i", $tmp, $m1)){

                                	$sc = $m1[1];


		}
		if(preg_match("/(.*) of (.*)/i", $sc, $m1)){

                                	$sc = $m1[2];
                                	$sc = preg_replace("/,/","",$sc);
                         }
//new
		$count = 1;
//nextline new			if(preg_match_all("/<li>(<a.*?)(<\/li>)/si", $tmp, $matches)){
		if(preg_match_all("/<h3>(<a.*?)(<ul>)/si", $tmp, $matches)){


			foreach($matches[1] as $st){
				if($count<=$num&&$count<=$sc){
//nextline new						if(preg_match("/^<a href=\"(.*?)\" class=\"t\"\s*>(.*?)<\/a>(.*?)<br\/>(.*?)<br\/>/si", $st, $m2)){
if(preg_match("/href=\"(.*?)\">(.*?)<\/a><\/h3><p>(.*?)<\/p>/si", $st, $m2)){
						$linkurl = $m2[1];
						$title = $m2[2];
						$summary = $m2[3];
						$category = "n/a";
					$results[$count] = array(
						"title"=>$title,
						"link"=>$linkurl,
						"summary"=>$summary,
						"category"=>$category
					);
					$count++;
					}
				}else{
					break;
				}
			}
			return $sc;
		}else return "";
	}else{
		return "";
	}
}

//END OF MSN

 

here is the XML search

//SEARCHFEED XML FEEDS
function GetSearchFeedResults(&$results, $ss, $start = 1, $num = 1){
	global $SEARCHFEED_URL, $TRY_CONNECTIONS, $TRY_PAUSE;
	global $SEARCHFEED_CID;
	$results = array(
							"0" => array(
							"title"=>"",
							"link"=>"",
							"summary"=>"",
							"category"=>"",
							"bid"=>""
						 )
	);
	//$SEARCHFEED_CID = GetSettings("searchfeed_id");
	$link = $SEARCHFEED_URL."cat=".urlencode($ss)."&pID=".$SEARCHFEED_CID."&IP=".getenv("REMOTE_ADDR")."&page=".($start)."&nl=".$num;
	$cc = 1;



	while(!($fh = @fopen($link, 'r'))){
		if($cc==$TRY_CONNECTIONS) break;
		$cc++;
		Pause($TRY_PAUSE);
	}
	if($fh)
	{
		$buff = "";
		$tmp = "";
		$tmp_arr = array();
		while($buff = fread($fh, 256)){
			$tmp.=$buff;
		}
		fclose($fh);
/*//
						print "SF working...<hr>";
						$ft = fopen("temp2.txt","a");
						fwrite($ft, "\n\n$link\n\n");
						fwrite($ft, $tmp);
						fclose($ft);
*/
		$sc = $num;
		$count = 1;
		if(preg_match("/<Listings>(.*)<\/Listings>/is", $tmp, $matches)){
			$recs = $matches[1];
				if(preg_match("/<Count>(.*?)<\/Count>/is", $recs, $m1)){
					$sc = $m1[1];
				}
				if(preg_match_all("/<Listing>(.*?)<\/Listing>/is", $recs, $m1)){
					foreach($m1[1] as $tt){
						if(preg_match("/<URI>\s*(.*)\s*<\/URI>/is", $tt, $m2)){
							$linkurl = $m2[1];
						}
						if(preg_match("/<URL>\s*(.*)\s*<\/URL>/is", $tt, $m2)){
							$category = $m2[1];
						}
						if(preg_match("/<Title>\s*<!\[CDATA\[(.*)\]\]>\s*<\/Title>/is", $tt, $m2)){
							$title = $m2[1];
						}
						if(preg_match("/<Description>\s*<!\[CDATA\[(.*)\]\]>\s*<\/Description>/is", $tt, $m2)){
							$summary = $m2[1];
						}
						if(preg_match("/<Bid>\s*(.*)\s*<\/Bid>/is", $tt, $m2)){
							$bid = $m2[1];
						}
/*
						$ft = fopen("temp.txt","a");
						fwrite($ft, "$title\n$summary\n$linkurl\n$category\n$bid\n---------------------------\n");
						fclose($ft);
*/
						$results[$count] = array(
							"title"=>$title,
							"link"=>$linkurl,
							"summary"=>$summary,
							"category"=>$category,
							"bid"=>$bid
						);
						$count++;
					}
				}
			return $sc;
		}else return "";
	}else{
		return "";
	}
}
//END OF SEARCHFEEDS XML FEEDS

Link to comment
Share on other sites

Okay, I may have solved my own problem but I'm not sure yet.

An html page calls the index script by linking to it and setting some variables. example:

 

http://www.buildbig.org/main/index.php?ss=Auto+Dealers&cmd=1

 

however now believe this is incorrect because when I echo $ss in the script that it's passing to I get nothing, furthermore the condition if (isset($ss)) returns false.

 

Can somebody tell me the correect way to call a script with a link and then after the link set the variable ss to a given string like "Auto Dealers" and the variable cmd to 1.

 

also for some reason i have another version of the script that says this:

 

http://www.buildbig.org/main/index.php?ss=Auto+Wrecking&cmd=1

Link to comment
Share on other sites

Are you using $ss (with register_globals on) or $_REQUEST['ss'] (will work even with register_globals off) ?

 

About the &, it's fine to have & in the html.  & is the html entity for the ampersand, "&".  It all depends on where that url is.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.