Ver Mensaje Individual
  #10 (permalink)  
Antiguo 09/01/2003, 22:03
Sandungas
 
Fecha de Ingreso: diciembre-2002
Mensajes: 23
Antigüedad: 23 años, 9 meses
Puntos: 0
Gracias Herminio. Con el set_time_limit he conseguido poder resolver el problema de archivos más grandes, pero aún así, no puedo procesar archivos muy grandes (+100 enlaces).

El código q has posteado no me funciona por otra parte. De todas formas gracias a todos por su ayuda.

Ahora necesito acelerar la ejecución del script. Una posibilidad es q en lugar de efectuar 1 conexión con una página, y comprobar su html, pudiera acceder a varias simultaneamente, aunq esto no sé si aumentaría la velocidad o la dejaría igual.

Posteo el código tal como está actualmente.

Código PHP:
<?php 
if (getenv('REQUEST_METHOD') == 'POST') { 
  
$url = $_POST[url]; 
  
$reciproco = $_POST[reciproco];
} else { 
  
$url = $_GET[url]; 
  
$reciproco = $_GET[reciproco];
} 
?> 

<form action="<?= $PHP_SELF ?>" method="POST">
  <div align="center">
    <table width="75%" border="0" cellspacing="5" cellpadding="0">
<tr>
        <td width="12%">URL:</td>
        <td width="88%"> <input name="url" type="text" value="<?= $url ?>" size="80"/></td>
      </tr>
      <tr>
        <td>Texto:</td>
        <td><input name="reciproco" type="text" value="<?= $reciproco ?>" size="80"/></td>
      </tr>
    </table>
<input type="submit">
  </div>
</form> 

<?php

  set_time_limit
(0);  
  
// Función para comprobar si existe un determinado texto (enlace) en una url
function recip($surl,$reciproco){
    
$fd = fopen ("$surl", "r");
    while (!
feof ($fd)) 
    {
        
$buffer = fgets($fd, 4096);
        if (
strstr($buffer,$reciproco))
            return 
true;
    }
    
fclose ($fd);
}

//Borramos de un array los elementos que tengan reciproco
function borrar(&$ahrefs,&$alinks,$reciproco){
    
$x=0;    
    while(
$x<sizeof($ahrefs))
    {
    if (
recip($ahrefs[$x],$reciproco) == true){
        
array_splice($ahrefs,$x,1);
        
array_splice($alinks,$x,1);}
    else
        
$x++; 
    }
}

  
// Separamos el código html (hrefs y links) 
  
if ($url) { 
  
$remote = fopen($url, 'r'); 
  
$data = fread($remote, 1048576); 
  
fclose($remote); }

  unset(
$location); 
  
$links = array();  // Array con la descripción de los links 
  
$hrefs = array();  // Array de urls
  
$pos = 0; 
  while (!((
$pos = strpos($data,"<",$pos)) === false)) { 
    
$pos++; 
    
$endpos = strpos($data,">",$pos); 
    
$tag = substr($data,$pos,$endpos-$pos); 
    
$tag = trim($tag); 
    if (isset(
$location)) {  // Buscamos </A> 
      
if (!strcasecmp(strtok($tag," "),"/A")) { 
        
$link = substr($data,$linkpos,$pos-1-$linkpos); 
        
$links[] = $link; 
        
$hrefs[] = $location; 
        unset(
$location); 
      } 
      
$pos = $endpos+1; 
    } else {  
// Buscamos <A ...> 
      
if (!strcasecmp(strtok($tag," "),"A")) { 
        if (
eregi("HREF[ \t\n\r\v]*=[ \t\n\r\v]*\"([^\"]*)\"",$tag,$regs)); 
        else if (
eregi("HREF[ \t\n\r\v]*=[ \t\n\r\v]*([^ \t\n\r\v]*)",$tag,$regs)); 
        else 
$regs[1] = ""; 
        if (
$regs[1]) {  
          
$location = $regs[1]; 
        } 
        
$pos = $endpos+1; 
        
$linkpos = $pos; 
      } else { 
        
$pos = $endpos+1; 
      } 
    } 
  } 
  
borrar($hrefs,$links,$reciproco);
for (
$i=0; $i<sizeof($links); $i++) { 
    echo 
"<A HREF=\"".$hrefs[$i]."\">".$links[$i]."</A><BR>\n"; 
  } 
?>
Si a alguien se le ocurre algo gracias por adelantado.