elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Sigue las noticias más importantes de seguridad informática en el Twitter! de elhacker.NET


+  Foro de elhacker.net
|-+  Programación
| |-+  Desarrollo Web
| | |-+  PHP (Moderador: #!drvy)
| | | |-+  Carga Asyncronica Json
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Carga Asyncronica Json  (Leído 2,051 veces)
.:Weeds:.

Desconectado Desconectado

Mensajes: 122



Ver Perfil
Carga Asyncronica Json
« en: 7 Noviembre 2013, 22:48 pm »

Tengo el siguiente codigo.
Código
  1. <?
  2. function get_tweets($url) {
  3.  
  4.    $json_string = file_get_contents('http://urls.api.twitter.com/1/urls/count.json?url=' . $url);
  5.    $json = json_decode($json_string, true);
  6.  
  7.    return intval( $json['count'] );
  8. }
  9.  
  10. function get_likes($url) {
  11.  
  12.    $json_string = file_get_contents('http://graph.facebook.com/?ids=' . $url);
  13.    $json = json_decode($json_string, true);
  14.  
  15.    return intval( $json[$url]['shares'] );
  16. }
  17.  
  18. function get_plusones($url) {
  19.  
  20.    $curl = curl_init();
  21.    curl_setopt($curl, CURLOPT_URL, "https://clients6.google.com/rpc");
  22.    curl_setopt($curl, CURLOPT_POST, 1);
  23.    curl_setopt($curl, CURLOPT_POSTFIELDS, '[{"method":"pos.plusones.get","id":"p","params":{"nolog":true,"id":"' . $url . '","source":"widget","userId":"@viewer","groupId":"@self"},"jsonrpc":"2.0","key":"p","apiVersion":"v1"}]');
  24.    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  25.    curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
  26.    $curl_results = curl_exec ($curl);
  27.    curl_close ($curl);
  28.  
  29.    $json = json_decode($curl_results, true);
  30.  
  31.    return intval( $json[0]['result']['metadata']['globalCounts']['count'] );
  32. }
  33. function get_shares($url) {    
  34.  $json_string = file_get_contents("http://www.linkedin.com/countserv/count/share?url=$url&format=json");
  35.  $json = json_decode($json_string, true);
  36.  return intval( $json['count'] );
  37. }
  38. ?>
  39.  

El code funciona de maravilla pero hasta que no carga el json no empieza a cargar la web, lo que hace que se haga bastante lenta, como podria hacerlo asyncronicamente? Estoy empezando con php.

Saludos y gracias.


En línea


Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
[C#] Deserializar JSON
.NET (C#, VB.NET, ASP)
Siuto 1 4,783 Último mensaje 9 Septiembre 2010, 17:55 pm
por [D4N93R]
[PETICION] Conversor XML a JSON
Programación General
RyogiShiki 2 3,579 Último mensaje 13 Noviembre 2011, 00:32 am
por RyogiShiki
json
Desarrollo Web
samrofi 0 1,718 Último mensaje 8 Agosto 2012, 16:31 pm
por samrofi
¿por qué usar xml en vez de json?
Desarrollo Web
Developer Diego 4 3,464 Último mensaje 21 Abril 2013, 04:47 am
por Developer Diego
Editar Json .net 2.0
.NET (C#, VB.NET, ASP)
.:Weeds:. 0 1,563 Último mensaje 25 Agosto 2013, 21:50 pm
por .:Weeds:.
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines