Foros del Web » Programando para Internet » PHP »

Warning: file_get_contents

Estas en el tema de Warning: file_get_contents en el foro de PHP en Foros del Web. Estoy utilizando facebook comments en mis posts y encontré el siguiente código para obtener por php la cantidad de comentarios: Código PHP: <?php $query  =  ...
  #1 (permalink)  
Antiguo 07/06/2012, 10:23
 
Fecha de Ingreso: mayo-2012
Mensajes: 15
Antigüedad: 12 años
Puntos: 0
Pregunta Warning: file_get_contents

Estoy utilizando facebook comments en mis posts y encontré el siguiente código para obtener por php la cantidad de comentarios:
Código PHP:
<?php
$query 
urlencode("select commentsbox_count from link_stat where url = 'http://techcrunch.com/2012/03/31/dramacrunch/'");
$response json_decode(file_get_contents("https://graph.facebook.com/fql?q=$query"), TRUE);
if(!empty(
$response['data'][0]['commentsbox_count'])) {
    echo 
$response['data'][0]['commentsbox_count'] . " comments were found!";
}
?>
Lo modifiqué ya que la url debería ser dinámica:
Código PHP:
<?php
$url 
urlencode(get_permalink($post->ID));
$query urlencode("select commentsbox_count from link_stat where url = '$url'");
$response json_decode(file_get_contents("https://graph.facebook.com/fql?q=$query"), TRUE);
echo 
$response['data'][0]['commentsbox_count'];
?>
Funciona aveces y otras veces me aparece una advertencia:

Warning: file_get_contents() [function.file-get-contents]: php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution in /www/patricioherrera.com.ar/htdocs/wp-content/themes/ph/index.php on line 50

Warning: file_get_contents(https://graph.facebook.com/fql?q=select+commentsbox_count+from+link_stat+wher e+url+%3D+%27http%253A%252F%252Fpatricioherrera.co m.ar%252Fwork-number-3%252F%27) [function.file-get-contents]: failed to open stream: php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution in /www/patricioherrera.com.ar/htdocs/wp-content/themes/ph/index.php on line 50


La línea 50 es esta:
Código PHP:
$response json_decode(file_get_contents("https://graph.facebook.com/fql?q=$query"), TRUE); 
Cuál es el motivo?
Estoy cometiendo algún error al modificarlo?

Muchas gracias.
  #2 (permalink)  
Antiguo 07/06/2012, 10:27
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: Warning: file_get_contents

El error no es de código, simplemente en ocasiones se conecta bien y en otras no.

Modificando el código no va a solucionar nada, en dado caso deberías hacer uso de cURL o sockets para solventar la desventaja de file_get_contents().
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #3 (permalink)  
Antiguo 07/06/2012, 10:34
 
Fecha de Ingreso: mayo-2012
Mensajes: 15
Antigüedad: 12 años
Puntos: 0
Respuesta: Warning: file_get_contents

Gracias por tu respuesta, voy a verificar esas soluciones :)
  #4 (permalink)  
Antiguo 07/06/2012, 10:43
 
Fecha de Ingreso: mayo-2012
Mensajes: 15
Antigüedad: 12 años
Puntos: 0
Respuesta: Warning: file_get_contents

Me podrías dar una mano de como usar el metodo cURL en mi caso?

Etiquetas: warning
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 11:42.