Connecting Tech Pros Worldwide Forums | Help | Site Map

execution time reduce

Member
 
Join Date: Feb 2008
Location: chennai
Posts: 35
#1: Jul 1 '08
hi,
i use php for searching keyword in word document.but it more time to get a output how will reduce the execution time..
Expand|Select|Wrap|Line Numbers
  1. if($open=opendir($namedir))
  2.                 {
  3.                     while($filedir=readdir($open))
  4.                     {
  5.                         if($filedir!="." && $filedir!="..")
  6.                         {
  7.                             $name=$namedir."/".$filedir;
  8.                             //$handle=fopen("$filedir","r");
  9.                             $filedata=file_get_contents($name); 
  10.                              for($count=0;$count<count($arraykey);$count++)
  11.                                 {
  12.                                     if(preg_match("/\b$arraykey[$count]\b/i","$filedata"))
  13.                                     {
  14.                                       $match[]="true";
  15.                                     } 
  16.                                     else
  17.                                     {
  18.                                         $match[]="flase";
  19.                                     }                                        
  20.                                 }
  21.                                 if(($andkey=="and") and ($orkey=="or"))
  22.                                 {
  23.                                     for($countno=0;$countno<count($arraykey);$countno++)
  24.                                     {
  25.                                         if($key[$countno]=="and")
  26.                                         {
  27.                                             $andval++;
  28.                                             if($match[$countno]=="true")
  29.                                             {
  30.                                                 $value++;
  31.                                             }                                            
  32.                                         }
  33.                                         else if($key[$countno]=="or")
  34.                                         {                                            
  35.                                             if($match[$countno]=="true")
  36.                                             {
  37.                                                 $valueno++;
  38.                                             }
  39.                                         }                                        
  40.                                     }
  41.                                     if($andval==$value and $valueno > 1)
  42.                                         {
  43.                                             $flag="ok";
  44.                                         }
  45.                                         else
  46.                                         {
  47.                                             $flag="not";
  48.                                         }
  49.                                 }
  50.                                 else if(($andkey=="and") and ($orkey==NULL))
  51.                                 {                                
  52.                                     for($countno=0;$countno<count($arraykey);$countno++)
  53.                                     {
  54.                                             if($match[$countno]=="true")
  55.                                             {
  56.                                                 $value++;
  57.                                             }
  58.  
  59.                                     }                                    
  60.                                         if(count($arraykey)==$value )
  61.                                         { 
  62.                                             $flag="ok";
  63.                                         }
  64.                                         else
  65.                                         {
  66.                                             $flag="not";
  67.                                         }                                                                        
  68.                                 }
  69.                                 else if(($orkey=="or") and ($andkey==NULL))
  70.                                 {                                    
  71.                                      for($countno=0;$countno<count($arraykey);$countno++)
  72.                                     {
  73.                                             if($match[$countno]=="true")
  74.                                             {
  75.                                                 $value++;
  76.                                             }                
  77.  
  78.                                     }
  79.                                         if($value >= 1)
  80.                                         {
  81.                                             $flag="ok";
  82.                                         }
  83.                                         else
  84.                                         {
  85.                                             $flag="not";
  86.                                         }
  87.                                 }
  88.                                 else if($andkey==NULL and $orkey==NULL)
  89.                                 {
  90.                                     for($co=0;$co<count($arraykey);$co++)
  91.                                     {        
  92.                                         if($match[$co]=="true")
  93.                                         {
  94.                                         $valdata++;
  95.                                         }                                    
  96.                                     }
  97.                                         if(count($arraykey)==$valdata)
  98.                                         {
  99.                                             $flag="ok";
  100.                                         }
  101.                                         else
  102.                                         {
  103.                                             $flag="not";
  104.                                         }
  105.                                 }
  106.                                 if($flag=="ok")
  107.                                 {        $i++;
  108. //                                    echo $filedir."<br>";                                    
  109.                                     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>";                                 
  110.                                 }
  111.                                 unset($match,$flag,$vardata,$count,$valueno,$value,$andval,$valdata);                         
  112.                         }

pbmods's Avatar
Site Moderator
 
Join Date: Apr 2007
Location: Texas
Posts: 5,435
#2: Jul 1 '08

re: execution time reduce


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/).
Member
 
Join Date: Feb 2008
Location: chennai
Posts: 35
#3: Jul 2 '08

re: execution time reduce


Quote:

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..........
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#4: Jul 2 '08

re: execution time reduce


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.
pbmods's Avatar
Site Moderator
 
Join Date: Apr 2007
Location: Texas
Posts: 5,435
#5: Jul 3 '08

re: execution time reduce


Quote:

Originally Posted by shanmugamit

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

Ugg time to talk to my hosting provider... again...

http://blog.pbmods.com/2007/11/27/wh...lopers-part-1/
Reply