execution time reduce

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shanmugamit
    New Member
    • Feb 2008
    • 45

    #1

    execution time reduce

    hi,
    i use php for searching keyword in word document.but it more time to get a output how will reduce the execution time..
    Code:
    if($open=opendir($namedir))
    				{
    					while($filedir=readdir($open))
    					{
    						if($filedir!="." && $filedir!="..")
    						{
    							$name=$namedir."/".$filedir;
    							//$handle=fopen("$filedir","r");
    							$filedata=file_get_contents($name); 
    							 for($count=0;$count<count($arraykey);$count++)
    								{
    									if(preg_match("/\b$arraykey[$count]\b/i","$filedata"))
    									{
    									  $match[]="true";
    									} 
    									else
    									{
    										$match[]="flase";
    									}										
    								}
    								if(($andkey=="and") and ($orkey=="or"))
    								{
    									for($countno=0;$countno<count($arraykey);$countno++)
    									{
    										if($key[$countno]=="and")
    										{
    											$andval++;
    											if($match[$countno]=="true")
    											{
    												$value++;
    											}											
    										}
    										else if($key[$countno]=="or")
    										{											
    											if($match[$countno]=="true")
    											{
    												$valueno++;
    											}
    										}										
    									}
    									if($andval==$value and $valueno > 1)
    										{
    											$flag="ok";
    										}
    										else
    										{
    											$flag="not";
    										}
    								}
    								else if(($andkey=="and") and ($orkey==NULL))
    								{								
    									for($countno=0;$countno<count($arraykey);$countno++)
    									{
    											if($match[$countno]=="true")
    											{
    												$value++;
    											}
    											
    									}									
    										if(count($arraykey)==$value )
    										{ 
    											$flag="ok";
    										}
    										else
    										{
    											$flag="not";
    										}																		
    								}
    								else if(($orkey=="or") and ($andkey==NULL))
    								{									
    									 for($countno=0;$countno<count($arraykey);$countno++)
    									{
    											if($match[$countno]=="true")
    											{
    												$value++;
    											}				
    									
    									}
    										if($value >= 1)
    										{
    											$flag="ok";
    										}
    										else
    										{
    											$flag="not";
    										}
    								}
    								else if($andkey==NULL and $orkey==NULL)
    								{
    									for($co=0;$co<count($arraykey);$co++)
    									{		
    										if($match[$co]=="true")
    										{
    										$valdata++;
    										}									
    									}
    										if(count($arraykey)==$valdata)
    										{
    											$flag="ok";
    										}
    										else
    										{
    											$flag="not";
    										}
    								}
    								if($flag=="ok")
    								{		$i++;
    //									echo $filedir."<br>";									
    									print"<input type=\"checkbox\" value=\"$name\" id=\"name$i\" name=\"ss\"><a href=\"#\" id=\"link$i\" onClick=\"fnopen('$name','$aa')\" onDblClick=\"fnword('$name')\">$filedir</a><br>";								 
    								}
    								unset($match,$flag,$vardata,$count,$valueno,$value,$andval,$valdata); 						
    						}
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Heya, shanmugamit.

    Have a look at this article to find out how to speed up the for loop in your code (http://todofixthis.com/2007/11/27/wh...lopers-part-1/).

    Comment

    • shanmugamit
      New Member
      • Feb 2008
      • 45

      #3
      Originally posted by pbmods
      Heya, shanmugamit.

      Have a look at this article to find out how to speed up the for loop in your code (http://todofixthis.com/2007/11/27/wh...lopers-part-1/).

      hi,
      that link not open..........

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Split the code into logical functions that perform a logical task.
        You can then use some logging/debugging to pin point which function or loop is causing the delay.

        Comment

        • pbmods
          Recognized Expert Expert
          • Apr 2007
          • 5821

          #5
          Originally posted by shanmugamit
          hi,
          that link not open..........
          Ugg time to talk to my hosting provider... again...

          Comment

          Working...