Ver Mensaje Individual
  #7 (permalink)  
Antiguo 16/05/2011, 20:12
LhaN
 
Fecha de Ingreso: septiembre-2008
Mensajes: 148
Antigüedad: 15 años, 7 meses
Puntos: 10
Respuesta: Problemas al generar un log en txt (doble log)

Me hablaste en chino basico, solo se ingles y castellano :P, no en serio, no entendi ni lo de ejecutar el codigo en consola ni lo de prefetching, soy novato.

Pero encontre el problema...
Código PHP:
Ver original
  1. <?
  2. function caracteresAleatorios($caracteres,$length){
  3.     $randhexa='';
  4.     for($i=0;$i<$length;$i++)
  5.         $randhexa = $randhexa.substr($caracteres,rand(0,strlen($caracteres)-1),1);
  6.     return $randhexa;
  7. }
  8.  
  9. function alfanumerico($length){
  10.     $alfanumerico='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  11.     return caracteresAleatorios($alfanumerico,$length);
  12. }
  13.  
  14. class Clase{
  15.     var $cad;
  16.     function Clase(){
  17.         $this->cad=alfanumerico(5);
  18.         $file=fopen('algo'.$this->cad.'.txt','a+');
  19.         for($i=1;$i<10;$i++)
  20.             fwrite($file,'Linea '.$i.chr(13).chr(10));
  21.         fclose($file);
  22.         $this->crearImagen();
  23.     }
  24.     function crearImagen(){
  25.         $img=imagecreatetruecolor(100,100);
  26.         imagepng($img, "salida".$this->cad.".png");
  27.         //header('Content-Type: image/png');
  28.         imagepng($img);
  29.         imagedestroy($img);
  30.     }
  31. }
  32. $c=new Clase();
  33. ?>

Si prueban esto y le descomentan la linea del header() resulta que en el log pone linea del 1 al 9 y luego repite de nuevo... lo mismo que me sucede en mi otro php. En el otro php al tener datos random (hay una celda distinta de las demás) se verifica que la imagen solo se crea una vez, y que el primer log es el que le corresponde, en este caso no, por que la imagen es negra y el log muy genérico.

EDITADO:
si modifican $this->cad=alfanumerico(5).date('His'); crea 2 logs y 2 imagenes...

EDITADO2:
No es un bug...
Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include(), or require(), functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.

Última edición por LhaN; 16/05/2011 a las 20:21