SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Zealot stuffedbuggy's Avatar
    Join Date
    Sep 2008
    Posts
    187
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation help ! php script runs forever..

    I have a script which populates my database with links and title's from other pages, it was working fine, but now it just acts like it keeps loading and loading. My host company said it was performing to many mysql transactions and using up cpu resources. How can I stop this???
    You know you cooler than me...

  2. #2
    SitePoint Wizard
    Join Date
    Oct 2005
    Location
    London
    Posts
    1,678
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Some code would probably help you get a helpful answer here

  3. #3
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Simple steps:
    1. Highlight your source code
    2. Hold down Ctrl
    3. Press C
    4. Release Ctrl
    5. Type the following characters in the 'quick reply' box below, without spaces: [ p h p ].
    6. Hold down Ctrl
    7. Press V
    8. Release Ctrl
    9. Type the following characters in the 'quick reply' box below, without spaces: [ / p h p ].
    10. Press 'Post Quick Reply'
    11. Be patient and wait for an answer


    Basically my point is that we cannot give you any help without knowing what your code is.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  4. #4
    SitePoint Zealot stuffedbuggy's Avatar
    Join Date
    Sep 2008
    Posts
    187
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <?php ob_start();
    ini_set('memory_limit','24M');
    set_time_limit (60);
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    
    <html>
    
    <head>
    <meta http-equiv="content-type" content="text/html;charset=UTF-8">
    <meta name="description" content="">
    <meta name="keywords" content="">
    
    <title> Search Info</title>
    <style type="text/css">
    </style>
    <?php
    $infocon=include('admin/somescript.php');
    $conn=include('admin/somescript.php');
    ?>
    </head>
    <body>
    
    <?php
    
    if(!$infocon){
       echo"could not connect";
       header( 'Location: http://' );
       exit('redirecting...connection not available');
       }
    elseif(!$conn){
       echo"could not connect";
       header( 'Location: http://www.' );
       exit('redirecting...connection not available');
       }
    else{
       echo"Connection Successful...<br>";
       }
         $query = "SELECT entry, link, relevance FROM tablel WHERE complete NOT LIKE 'yes' ORDER BY entry DESC LIMIT 1";
         $result = mysql_query($query);
         while($row = mysql_fetch_array($result,MYSQL_ASSOC)){
               $id = $row['entry'];
               $link = $row['link'];
               $relv = $row['relevance'];
               echo $id." <br> ".$link." <br> ".$relv;
         }
    if(!($id && $link && $relv)){
         echo"All reletive values could not be retrieved<br>";
         $del = mysql_query("DELETE FROM table where link = '$link'");
         if(!($del)){exit();}
         else{
         header( 'Location: http://' );
         exit('redirecting...VALUES not available');  
           }
         }
    else{
        $ipcheck = gethostbyname($link);
        echo "<br>The IP Address of $link is... $ipcheck<br>"; 
        $prefix = substr($ipcheck,0,3);
        $adjust = eregi_replace('(\.)',"",$prefix);
        echo "$adjust is the IP Prefix";
        }
    if(!($adjust)){
         echo"IP Prefix not accessible";
         $del = mysql_query("DELETE FROM table where link = '$link'");
         if(!($del)){exit();}
         else{
         header( 'Location: http://' );
         exit('redirecting...IP Prefix not available');  
           }
        }  
    else{
         $ip=array(1=>'204','205','206','207','208','209','216','199','63','64','65','66','67','68','69','70','71','72','73',
    '74','75','76','96','97','98','99','128','129','130','131','132','134','135','136','137','138','139','140','142','143',
    '144','146','147','148','149','152','155','156','157','158','159','160','161','162','164','165','166','167','168','169',
    '170','172','173','174');
         foreach($ip as $key => $value){
              if($adjust == $value){
              echo"<br>This IP is accepted<br>";
              $ipaccept = 'accepted';
              }
              }
         } 
    if(!($ipaccept)){
         $del = mysql_query("DELETE FROM table where link = '$link'");
         if(!($del)){exit();}
         else{
         header( 'Location: http://' );
         exit('redirecting...VALUES not available');  
           }
         }
    else{
         $actualurl = 'http://'.$link;
         if(!($source = file_get_contents($actualurl))){
         $del = mysql_query("DELETE FROM table where link = '$link'");
         }
         }       
    if(!($source)){
        $del = mysql_query("DELETE FROM table where link = '$link'");
         if(!($del)){exit('Could not delete due to unavailable source');}
         else{
         header( 'Location: http://' );
         exit('redirecting...VALUES not available');  
           }
         }
    else{
         eregi('<title>(.*)</title>',$source,$got);
         $title = ereg_replace('[[:blank:]]',' ',$got[1]);
         echo "<br>The Title is... <b>$title</b>";
         if(isset($title)){
              $del = mysql_query("UPDATE table SET title = '$title' WHERE link = '$link'");
              if(!($del)){
                  echo'Title could not be updated !';
                  $titlex = 'Untitled';                 
              $del2 = mysql_query("UPDATE table SET title = '$titlex' WHERE link = '$link'");
                   if(!($del2)){
                       echo'UPDATE WAS NOT SUCCESFUL';
                       $del = mysql_query("DELETE FROM table where link = '$link'");
                       header( 'Location: http://www.spongelink.com/redirect.php' );
              }
              
              }
           echo"<br>Title Update successful";
           $success = 'success';   
          }// end of internal if
         }// end of else        
    if(isset($success)){
         $match = preg_match_all('/>(.*?)</', $source, $matches);
         $max=array();
              foreach($matches[1] as $number => $value){
                   array_push($max,$value);
              }
              $new=array();
                   foreach(array_filter($max) as $kez => $value){
                        array_push($new,$value);
                   }
    
         $updt=substr($new[7].' '.$new[8].' '.$new[9].' '.$new[10].' '.$new[11],0,135);
         $finupdt=mysql_real_escape_string(strip_tags($updt));
         echo "<br><br>The Description is...<br> <b>$finupdt</b>";
         if(!($finupdt)){
             $finupdt = 'No Description Available';
         }
         $adddesc = mysql_query("UPDATE table SET description = '$finupdt' WHERE link = '$link'");
                   if(!($adddesc)){
                       echo'UPDATE WAS NOT SUCCESFUL';
                       $del = mysql_query("DELETE FROM table where link = '$link'");
                        header( 'Location: http://www.spongelink.com/redirect.php' );
                         
                   } 
       
                   $addcmplt = mysql_query("UPDATE table SET complete = 'yes' WHERE link = '$link'");
                        if(!($addcmplt)){
                             echo'UPDATE WAS NOT SUCCESFUL';
                             $del = mysql_query("DELETE FROM table where link = '$link'");
                             header( 'Location: http://www.spongelink.com/redirect.php' );
                         
                   } 
    echo"<br>Updates successful";
     
        
     } 
    header( 'refresh: 1; url=http://....redirect.php' );
    
    ob_end_flush();
    ?>
    
    </body>
    </head>
    </html>
    all the tables in queries are the same. also, i've removed certain hyperlinks(for security). thanks in advance for any help. the script was running fine this morning for hours, no delays or anything, then all of a sudden it's like it was bogging everything down.
    Last edited by stuffedbuggy; Oct 14, 2008 at 03:06.
    You know you cooler than me...

  5. #5
    SitePoint Zealot stuffedbuggy's Avatar
    Join Date
    Sep 2008
    Posts
    187
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I changed mysql_query to mysql_unbuffered_query, and added mysql_free_result to the script, performance has increased and is working fine now, and lowered my script time. Only time will tell if this solves the problem. Still other suggestions are most welcome.
    You know you cooler than me...

  6. #6
    SitePoint Zealot stuffedbuggy's Avatar
    Join Date
    Sep 2008
    Posts
    187
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well that didn't work, it ran great for about 30 minutes then come to a slow crawl again.
    You know you cooler than me...

  7. #7
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Try getting rid of that output buffering, using preg rather than ereg, using array_search rather than the foreach loop.

    Also, go through the script putting
    PHP Code:
    echo 'fine'; exit; 
    after every stage. Run the script, wait for it to say 'fine'. If it takes a while then you'll know where exactly the processing bottleneck is. If not, remove that line and put it after the next stage.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  8. #8
    SitePoint Member
    Join Date
    Oct 2008
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How many results is your query returning? It's possible that it's just processing NORMALLY but there is a lot of data to be processed.

  9. #9
    SitePoint Evangelist
    Join Date
    Jun 2006
    Location
    Wigan, Lancashire. UK
    Posts
    523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    foreach($ip as $key => $value){
       if(
    $adjust == $value){
          echo
    "<br>This IP is accepted<br>";
          
    $ipaccept 'accepted';
          break;
       }

    Break out of the foreach loop once you've found a match.

    Or even:
    PHP Code:
    $ipaccept in_array($adjust,$ip); 

  10. #10
    SitePoint Zealot stuffedbuggy's Avatar
    Join Date
    Sep 2008
    Posts
    187
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks to all once again. your help is much appreciated.
    You know you cooler than me...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •