Ver Mensaje Individual
  #4 (permalink)  
Antiguo 24/10/2009, 03:35
Avatar de neodani
neodani
 
Fecha de Ingreso: marzo-2007
Mensajes: 1.811
Antigüedad: 17 años, 2 meses
Puntos: 20
Respuesta: Optimizar script IMAP

En cambio en otro script que tengo donde no trato si tiene adjuntos o no, me carga 168 mensajes! en el mismo tiempo

La página fue creada en 25.0225231647 segundos

Parece que es la función de saber si tiene adjunto o no la que está dando problemas!!

¿Alguna idea de por qué me hace ir tan lento?


Código php:
Ver original
  1. <?$mtime = microtime(); $mtime = explode(" ",$mtime); $mtime = $mtime[1] + $mtime[0]; $tiempoinicial = $mtime; ?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <title>Chequear cuenta de correo</title>
  6. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  7. <link href="imap_css.css" rel="stylesheet" type="text/css" media="all" />
  8.  
  9. </head>
  10. <body>
  11. <h1 class="titulo"> Webmail BETA </h1>
  12.  
  13. <?
  14. $imap = imap_open ("{imap.gmail.com:993/imap/ssl}INBOX", "user", "pass") or die("No Se Pudo Conectar Al Servidor:" . imap_last_error());
  15. $checar = imap_check($imap);
  16.  
  17. // Detalles generales de todos los mensajes del usuario.
  18. $resultados = imap_fetch_overview($imap,"1:{$checar->Nmsgs}",0);
  19. // Ordenamos los mensajes de más nuevos a más antiguos
  20. krsort($resultados);
  21. $cont = 0;
  22.  
  23. // Informacion del mailbox
  24. $check = imap_mailboxmsginfo($imap);
  25.  
  26. echo "<div class='estadisticas'>";
  27. if ($check) {
  28.     echo "Fecha: "     . $check->Date    . "<br/>" ;
  29.     //echo "Driver: "   . $check->Driver  . "<br />\n" ;
  30.     //echo "Mailbox: "  . $check->Mailbox . "<br />\n" ;
  31.     echo "Total Mensajes: $check->Nmsgs | Sin Leer: $check->Unread | Recientes: $check->Recent | Eliminados: $check->Deleted <br/>";
  32.     echo "Tamaño buzón: " . $check->Size . "<br/><br/>" ;
  33. } else {
  34.     echo "imap_check() failed: " . imap_last_error() . "<br />\n";
  35. }
  36. echo "</div>";
  37.  
  38. // MOSTRAMOS EL MENSAJE
  39. echo "-------------------------------------------------------<br />";
  40. if (isset($_GET['num'])){
  41.     $num_mensaje=$_GET['num'];
  42.     echo "Mostrando cuerpo del mensaje #$num_mensaje<br/>";
  43.     $cont=0;
  44.     foreach ($resultados as $detalles) {
  45.         $cont = $cont + 1;
  46.         if ($cont == $num_mensaje){
  47.             $asunto=$detalles->subject;
  48.             echo "<p class='asunto'>$asunto</p>";}
  49.     }
  50.  
  51.     $section = 1;
  52.     $mensaje = imap_fetchbody($imap, $num_mensaje, $section);
  53.     echo nl2br(strip_tags($mensaje,'<p>')); // Util para los mensajes HTML, los transforma en texto plano
  54.    
  55. }else{
  56.     echo "Mensaje no encontrado<br/>";
  57. }
  58. echo "<br />-------------------------------------------------------<br />";
  59.  
  60. ?>
  61. <table class='tabla1'>
  62. <thead>
  63.     <tr>
  64.         <th scope="col" title="Mensaje">Msj</th>
  65.         <th scope="col" title="Remitente">Remitente</th>
  66.         <th scope="col" title="Asunto">Asunto</th>
  67.         <th scope="col" title="Tamaño">Tamaño</th>
  68.         <th scope="col" title="Fecha">Fecha</th>
  69.         <th scope="col" title="Leido">Leido</th>
  70.     </tr>
  71. </thead>   
  72. <?
  73. //$i=0;
  74. foreach ($resultados as $detalles) {
  75.     echo "<tr>";
  76.     //echo "Para: $detalles->to <br>";
  77.    
  78.     // Ponemos 'Sin asunto' en caso que no tenga.
  79.     if ($detalles->subject == ''){$subject='Sin asunto';}
  80.     else{
  81.         //Evita asuntos tipo =?ISO-8859-1?Q?B=F8lla?=
  82.         $subject = utf8_decode(imap_utf8($detalles->subject));
  83.     }
  84.     $from = utf8_decode(imap_utf8($detalles->from));
  85.    
  86.     // Mirar si tiene adjuntos
  87.     $msg_structure = imap_fetchstructure($imap, $detalles->msgno);
  88.    
  89.        
  90.        
  91.     echo "<td><b>#$detalles->msgno</b></td>";
  92.     echo "<td><b>$from</b></td>";
  93.     echo "<td><a href='correo_imap.php?num=$detalles->msgno'><b>$subject</b></a></td>";
  94.     //echo "<td><a href='mostrar_correo.php?msj=$detalles->msgno'><b>$subject</b></a></td>";
  95.     echo "<td><b>$detalles->size bytes</b></td>";
  96.     echo "<td><b>$detalles->date</b></td>";
  97.    
  98.    
  99.        
  100.     if($detalles->seen == "0") {
  101.         echo "<td><b>Sin leer</b></td>";
  102.         $cont = $cont + 1;
  103.     } else {
  104.         echo "<td>Leido</td>";
  105.     }
  106.    
  107.        
  108.     //$servidorenvia = strstr($detalles->message_id, '@');
  109.     //echo "Dominio Que Envia: $servidorenvia<br><hr>";
  110.     echo "</tr>";
  111.    
  112. //  $i=$i+1;
  113. //  $mi_array=array($i=>$detalles->msgno,$from,$subject,$detalles->size,$detalles->date);
  114.  
  115.    
  116.  
  117. }
  118. echo "</table>";
  119.  
  120. //foreach ($mi_array as $indice=>$actual)
  121. //    echo $actual . "<br>";
  122.    
  123.  
  124. imap_close($imap);
  125. $mtime = microtime(); $mtime = explode(" ",$mtime); $mtime = $mtime[1] + $mtime[0]; $tiempofinal = $mtime; $tiempototal = ($tiempofinal - $tiempoinicial); echo "La página fue creada en ".$tiempototal." segundos";
  126. ?>
  127. <div id="footer"> <p>Tratamiento de correo via IMAP - BETA 1.0</p></div>
  128. </body>
  129. </html>

Última edición por neodani; 24/10/2009 a las 03:48