Ver Mensaje Individual
  #1 (permalink)  
Antiguo 23/04/2014, 16:08
Avatar de sandrapatricia2468
sandrapatricia2468
 
Fecha de Ingreso: abril-2014
Mensajes: 7
Antigüedad: 10 años
Puntos: 0
Problemas con servidor web NGINX

Hola a todos...!
Tengo el siguiente archivo index.php

Código PHP:
Ver original
  1. <html>
  2.     <head>
  3.         <script stype="text/javascript">
  4.             function ventanachat(){
  5.                 var xmlHttp;
  6.                 if (window.XMLHttpRequest)
  7.                   {
  8.                   xmlHttp=new XMLHttpRequest();
  9.                   }
  10.                 else
  11.                   {
  12.                   xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  13.                   }
  14.                   var fetch_unix_timestamp ="";
  15.                     fetch_unix_timestamp = function()
  16.                         {
  17.                         return parseInt(new Date().getTime().toString().substring(0, 10))
  18.                         }
  19.                     var timestamp = fetch_unix_timestamp();
  20.                 xmlHttp.onreadystatechange=function(){
  21.                         if(xmlHttp.readyState==4){
  22.                             document.getElementById("ventanachat").innerHTML=xmlHttp.responseText;
  23.                             setTimeout('ventanachat()',10);
  24.                         }
  25.                        
  26.                         }
  27.                         xmlHttp.open("GET","db.php"+"?t="+timestamp,true);
  28.                     xmlHttp.send(null);
  29.             }
  30.             window.onload = function startrefresh(){
  31.                     setTimeout('ventanachat()',1000);
  32.                 }
  33.         </script>
  34.     </head>
  35.     <body>
  36.         <form action="insert.php" method="GET">
  37.         <input type="text" name="mensaje" id="enviachat" >
  38.             <input type="submit">
  39.         </form>
  40.         <div id="ventanachat" style="width:200px;height:200px;border:1px solid black;overflow:hidden;">
  41.             <script type="text/javascript">
  42.                 ventanachat();
  43.             </script>
  44.         </div>
  45.     </body>
  46. </html>

El siguiente archivo db.php:

Código PHP:
Ver original
  1. <?php
  2.  
  3. $conexion = mysql_connect("localhost","root","root");
  4. mysql_select_db("chat", $conexion) or die(mysql_error());
  5. //$conexion = sqlite_open('chat.db');
  6.  
  7. $consulta = "SELECT * FROM mensajes ORDER BY utc DESC LIMIT 5;";
  8.  
  9.  
  10. $resultado = mysql_query($consulta, $conexion) or die("Error en: $consulta: ".mysql_error());
  11. //$resultado = sqlite_query($conexion,$consulta);
  12.  
  13.  
  14. while($fila = mysql_fetch_array($resultado)){
  15.                            
  16.                                 echo $fila['utc'];
  17.                                 echo ' - ';
  18.                                 echo $fila['autor'];
  19.                                 echo ' - ';
  20.                                
  21.                                 echo $fila['mensaje'];
  22.                                 echo "<br>";
  23.  
  24.                            
  25.                         }
  26. mysql_close($conexion);
  27. //sqlite_close($conexion);
  28. ?>

y el ultimo archivo con nombre insert.php:

Código PHP:
Ver original
  1. <?php
  2.  
  3. $conexion = mysql_connect("localhost","root","root");
  4. mysql_select_db("chat", $conexion) or die(mysql_error());
  5. //$conexion = sqlite_open('chat.db');
  6. $consulta ="INSERT INTO mensajes VALUES ('".date('U')."','jocarsa','".$_GET['mensaje']."');";
  7.  
  8.  
  9. $resultado = mysql_query($consulta, $conexion);
  10. //$resultado = sqlite_exec($conexion,$consulta);
  11.  
  12.  
  13. //sqlite_close($conexion);
  14. mysql_close($conexion);
  15.  
  16. echo '<meta http-equiv="REFRESH" content="0;url=index.php">';
  17.  
  18. ?>

Es un chat muy sencillo que actualiza la pagina cada segundo para verificar si hay mensajes nuevos en la base de datos MySQL y mostrarlos. Lo probe con servidor apache y funciona de maravilla. Pero en el servidor web NGINX se queda pensando, y pensando y nada hace y deja de funcionar NGINX. No tengo idea cual sea el problema ('soy nueva en este mundillo' ), y espero me puedan ayudar. Gracias.