Ver Mensaje Individual
  #1 (permalink)  
Antiguo 26/08/2013, 11:59
BLADDE
 
Fecha de Ingreso: abril-2006
Mensajes: 72
Antigüedad: 18 años
Puntos: 0
problemas con comet, actualizacion en tiempo real

fijense amigos en mi servidor lo que tengo me funciona pero al pasarlo a produccion se me complica. existe una manera mejor?????
aqui los archivos que uso
en php
Código PHP:
<?php
function nuevo_iris($username)//nombre
 
{
     
     include_once 
'conexion.php';
    
     
$sql="select * from iris where recibe='$username' and (status='Asignada')";
                       
$consulta=mysql_query($sql) or die (mysql_error());  
                              if(
$res=mysql_fetch_object($consulta)){//verifico si hay algo nuevo
                              
return utf8_encode('Se genero una incidencia y se te asigno, la envia: '.$res->envia.
                             
' la descripcion cargada a dicha incidencia es:'.$res->nota.
                             
' dicha incidencia se asigno en fecha:'.$res->fecha.
                             
' recuerda es importante que continues la ruta de solución o cierres la incidencia en caso que te corresponda <a href="iris/index.php">Haz Click para ir a IRIS</a>');
                             }
                             
     
     }
     
     function 
nuevo_srp($username)//field2
 
{
    
$d$_SESSION['s_user_direccion'];
    
$de$_SESSION['s_user_dependencia'];
     include_once 
'conexion.php';
    
     
$sql="select proponente from srp where direccion='$d' and dependencia='$de' and status='0'";
                       
$consulta=mysql_query($sql) or die (mysql_error());  
                              if(
$res=mysql_fetch_object($consulta)){//veriifico si hay algo nuevo para cambiar la imagen
                              
return '<a href="srp/sslsrp/casa.php"><img src="images/srp_aviso.png" /></a>';
                             }else{return 
'<a href="srp/sslsrp/casa.php"><img src="images/srp.png" /></a>';}
                            
     
     }
     
     if(
$_GET)  
//$username=$_SESSION['s_user_username'];
    
set_time_limit(0);    
    
header("Edge-control: no-store");
    
usleep(10000);
    
$dw=0;
  
   if(
$_GET['opactu']==1)
   {
        
$content nuevo_iris($_SESSION["s_user_username"]);
    while(
$content=='')
    {
        
usleep(10000);
        
$content nuevo_iris($_SESSION["s_user_username"]);
    }
    echo 
$content;
       
       }
       if(
$_GET['opactu']==2)
   {
        
$content nuevo_srp($_SESSION["s_user_username"]);
    while(
$content=='')
    {
        
usleep(10000);
        
$content nuevo_srp($_SESSION["s_user_username"]);
    }
    echo 
$content;
       
       }
   
      
    exit();
}
/////////////////////////////////////////////// cierre actualizacion automatica //////////////////////////////////////////////////////////////////////////
?>
en js

Código:
<script>
function tildes_unicode(str){
	for(var i = 0; i < str.length; i++){
    str = str.replace('á','\u00e1');
	str = str.replace('é','\u00e9');
	str = str.replace('í','\u00ed');
	str = str.replace('ó','\u00f3');
	str = str.replace('ú','\u00fa');

	str = str.replace('Á','\u00c1');
	str = str.replace('É','\u00c9');
	str = str.replace('Í','\u00cd');
	str = str.replace('Ó','\u00d3');
	str = str.replace('Ú','\u00da');

	str = str.replace('ñ','\u00f1');
	str = str.replace('Ñ','\u00d1');
	}
	return str;
}
var xmlhttp = function()
    {
        var a;try{a = new XMLHttpRequest();}
        catch(e){try{a = new ActiveXObject('Msxml2.XMLHTTP');}
        catch(e){try{a = new ActiveXObject('Microsoft.XMLHTTP');}
        catch(e){alert('Tu navegador esta viejoo, descarga uno nuevo!!!');a=false;}
        }}return a;
    };  
    window.onload = function()
    {
        var iris = new comet_iris();// iris
		var srp = new comet_srp();// srp
		
    };  
	
    var comet_iris = function()
    {
		
        var iris = new xmlhttp();
        iris.open('GET',"pdc.php?opactu=1", true);
        iris.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
        iris.onreadystatechange = function()
        {
            if(iris.readyState == 4)
            {
				if(document.getElementById('sw_aviso33').value==0){
                document.getElementById('msj_iris').innerHTML = tildes_unicode(iris.responseText);
				$("#dialogModal_iris" ).dialog('open');
				document.getElementById('sw_aviso33').value=1;
				document.getElementById('img_iris').innerHTML='<a href="iris/index.php"><img src="iris/images/iris_msj.png" /></a>';
				window.setTimeout(function(){
					
                    iris = new comet_iris();                    
                },1000);
				}//fin si sw_aviso33
            }
        };
        iris.send('algo=algo');  
	              
    };
	
	 var comet_srp = function()
    {
		
        var srp = new xmlhttp();
        srp.open('GET',"pdc.php?opactu=2", true);
        srp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
        srp.onreadystatechange = function()
        {
            if(srp.readyState == 4)
            {
                document.getElementById('img_srp').innerHTML = tildes_unicode(srp.responseText);
				window.setTimeout(function(){
					
                    srp = new comet_srp();                    
                },1000);
                
            }
        };
        srp.send('algo=algo');  
		              
    };
	
	
</script>
no soy muy bueno en javascript quiza hay algo mas optimo que esto, en mi server local funciona muy bien pero al subirlo creo que genera mucho trafico