Ver Mensaje Individual
  #16 (permalink)  
Antiguo 30/09/2011, 00:49
Avatar de abimaelrc
abimaelrc
Colaborador
 
Fecha de Ingreso: mayo-2009
Ubicación: En el planeta de Puerto Rico
Mensajes: 14.734
Antigüedad: 15 años
Puntos: 1517
Respuesta: file_get_contents falla

Algo que se puede hacer es como indica andres, colocar un tiempo, pero añadiría que haga al menos tres veces la petición, con algo así
Código PHP:
Ver original
  1. <?php
  2. //ini_set('default_socket_timeout', 10);
  3. $context = stream_context_create(array('http' => array('timeout' => 10))); //timeout
  4. $xml_get = @file_get_contents("http://xml.e-travelsolution.com/xml/enginexml-agencies.asmx/getQuoteHotels?a=k4r3n-4n3l&pwd=5ecr370&c=PE&sd=20111111&ed=20111116&h=&rt=&mp=&r=1&r1a=2&r1k=0&r1k1a=-1&r1k2a=-1&r1k3a=-1&r2a=-1&r2k=-1&r2k1a=-1&r2k2a=-1&r2k3a=-1&r3a=-1&r3k=-1&r3k1a=-1&r3k2a=-1&r3k3a=-1&r4a=-1&r4k=-1&r4k1a=-1&r4k2a=-1&r4k3a=-1&r5a=-1&r5k=-1&r5k1a=-1&r5k2a=-1&r5k3a=-1&d=2&l=ESP&categoryid=&locationid=&chainid=&cityid=&fq=&co=MX", 0, $context);
  5.  
  6. if(!empty($xml_get)) {
  7.     $xml = new SimpleXMLElement($xml_get);
  8.     foreach ($xml->hotels->hotel as $item) {
  9.         $hoteles[] = array("idhotel" => (int) $item->hotelid,
  10.         "hotelname" => (string) ($item->hotelname), "ciudad" => (string) $item->cityname,
  11.         "ubicacionid" => (string) $item->ubicationid, "categoria" => (string) $item->categoryid,
  12.         "tarifaneta" => (int) $item->rooms->Roomrates->rate);
  13.     }
  14.     echo '<pre>';
  15.     print_r($hoteles);
  16.     echo '</pre>';
  17. }else{
  18.     $_SESSION['counter'] = !empty($_SESSION['counter']) ? ($_SESSION['counter'] + 1) : 1;
  19.     if($_SESSION['counter'] >= 3){
  20.         $_SESSION = array();
  21.         if (ini_get("session.use_cookies")) {
  22.             $params = session_get_cookie_params();
  23.             setcookie(session_name(), '', time() - 42000,
  24.                 $params["path"], $params["domain"],
  25.                 $params["secure"], $params["httponly"]
  26.             );
  27.         }
  28.         session_destroy();
  29.         echo "Lo sentimos el servidor esta ocupado en este momento";
  30.     }else{
  31.         header('Location: b.php');
  32.     }
  33. }
__________________
Verifica antes de preguntar.
Los verdaderos amigos se hieren con la verdad, para no perderlos con la mentira. - Eugenio Maria de Hostos

Última edición por abimaelrc; 30/09/2011 a las 00:58