1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

file_get_contents error

Discussion in 'Development' started by armagadon159753, Feb 12, 2018.

  1. armagadon159753

    armagadon159753 Zombie

    Messages:
    217
    GitHub:
    armagadon159753
    Error:
    PHP:
    [14:47:52] [Server thread/CRITICAL]: ErrorException"file_get_contents(): php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution" (EXCEPTIONin "UserGeo-master/src/UserGeo/Main" at line 51
    code:
    PHP:
    $data json_decode(file_get_contents("http://ipinfo.io/" $player_ip), true);[/U]
     
  2. 0x15f

    0x15f Baby Zombie

    Messages:
    145
    GitHub:
    0x15f
    PHP was unable to get the auctual IP address of the site.
     
  3. armagadon159753

    armagadon159753 Zombie

    Messages:
    217
    GitHub:
    armagadon159753
    They are an other way?
     
  4. 0x15f

    0x15f Baby Zombie

    Messages:
    145
    GitHub:
    0x15f
    That exception is thrown when PHP is unable to lookup the domain name. Use an IP lookup service and get the IP of the site and use it over the domain.
     
  5. Awzaw

    Awzaw Zombie Pigman Poggit Admin

    Messages:
    726
    GitHub:
    awzaw
    Did it ever work? If not, check that allow_url_fopen is enabled in php.ini.

    Alternatively you can use cURL. Using an IP address instead is not a good idea, unless you are sure their IP never changes...

    Also, we can't tell from the code you posted, but you should handle exceptions for file_get_contents, and use AsyncTask for any Web requests made by plugins.
     
  6. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Check your firewall settings. See if your server can access the outside world.
     
    xXNiceAssassinlo YT and Awzaw like this.
  7. kenygamer

    kenygamer Banned Banned

    Messages:
    106
    GitHub:
    kenygamer
    Restart PHP.
     
  8. armagadon159753

    armagadon159753 Zombie

    Messages:
    217
    GitHub:
    armagadon159753
    Wath do you mean by restart
    I juste restart the server after change
     
  9. 0x15f

    0x15f Baby Zombie

    Messages:
    145
    GitHub:
    0x15f
    If you're using PHP-FPM it needs to be restarted/reloaded. If not OPCache may need to be cleared for the changes to go into effect.
     
  10. kenygamer

    kenygamer Banned Banned

    Messages:
    106
    GitHub:
    kenygamer
    https://serverfault.com/a/189961
     
  11. Awzaw

    Awzaw Zombie Pigman Poggit Admin

    Messages:
    726
    GitHub:
    awzaw
    No need to restart anything except pocketmine. As sofe suggested, check your firewall allows http traffic.
     
  12. armagadon159753

    armagadon159753 Zombie

    Messages:
    217
    GitHub:
    armagadon159753
    I have no way of configuring my firewall in the client area of my host. I'm waiting for their answer
     
  13. kenygamer

    kenygamer Banned Banned

    Messages:
    106
    GitHub:
    kenygamer
    Unless you are not using the bin folder.
     
    0x15f likes this.
  14. armagadon159753

    armagadon159753 Zombie

    Messages:
    217
    GitHub:
    armagadon159753
    This issu is solved but i have an other one
    Old issu:
    In resolv.conf i juste added '
    nameserver 208.67.222.222'

    New issu
    PHP:
    [00:32:04] [Server thread/CRITICAL]: Unhandled exception executing command 'geo arm city' in usergeoTrying to get property 'city' of non-object                                                           [00:32:04] [Server thread/CRITICAL]: ErrorException"Trying to get property 'city' of non-object" (EXCEPTIONin "UserGeo-master/src/UserGeo/Main" at line 53
    PHP:
    $player_display_name $player->getName();
                
    $player_ip $player->getAddress();
                
    $data file_get_contents("http://ipinfo.io/" $player_ip "/json");
                
    $player_city $data->city;
                
    $player_hostname $data->hostname;
                
    $player_region $data->region;
                
    $player_country $data->country;
     
  15. 0x15f

    0x15f Baby Zombie

    Messages:
    145
    GitHub:
    0x15f
    PHP has a Geo library for such things. $data is JSON it needs to be decoded.
     
    kenygamer likes this.
  16. kenygamer

    kenygamer Banned Banned

    Messages:
    106
    GitHub:
    kenygamer
    Only this line and you're all set.
    PHP:
    $data json_decode($datatrue);
     
    SOFe likes this.
  17. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    He's using the value as an object, so $assoc should be false (default) instead of true.
     
    0x15f and kenygamer like this.
  18. armagadon159753

    armagadon159753 Zombie

    Messages:
    217
    GitHub:
    armagadon159753
    I have this error when i try go get the hostname.

    PHP:
    [09:24:10] [Server thread/CRITICAL]: Unhandled exception executing command 'usergeo VirVoltaSurMC Franche-ComtĂ©' in usergeoUndefined propertystdClass::$hostname
    [09:24:10] [Server thread/CRITICAL]: ErrorException"Undefined property: stdClass::$hostname(EXCEPTIONin "UserGeo-master/src/UserGeo/Main" at line 49
    PHP:
    $player_display_name $player->getName();
                
    $player_ip $player->getAddress();
                
    $data file_get_contents("http://ipinfo.io/" $player_ip);
                
    $json json_decode($datafalse);
                
    $player_city $json->city;
                
    $player_hostname $json->hostname;//error here
                
    $player_region $json->region;
                
    $player_country $json->country;
     
  19. Flavius12

    Flavius12 Spider Jockey

    Messages:
    32
    GitHub:
    flavius12
    It seems it's not defined. I reccomend you doing var_dump($json) to see all defined keys on $json data array
     
  20. armagadon159753

    armagadon159753 Zombie

    Messages:
    217
    GitHub:
    armagadon159753
    PHP:
    object(stdClass)#16263 (8) {
      
    ["ip"]=>
      
    string(12""
      
    ["hostname"]=>
      
    string(24""
      
    ["city"]=>
      
    string(7""
      
    ["region"]=>
      
    string(18""
      
    ["country"]=>
      
    string(2""
      
    ["loc"]=>
      
    string(15""
      
    ["org"]=>
      
    string(14""
      
    ["postal"]=>
      
    string(5""
    }
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.