PHP code example of phpgt / filecache

1. Go to this page and download the library: Download phpgt/filecache library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

phpgt / filecache example snippets


$ipAddress = $_SERVER["REMOTE_ADDR"];
$fileCache = new Gt\FileCache\Cache("/tmp/ip-address-geolocation");

// This function uses file_get_contents to contact the remote server
// at ipinfo.io, a costly operation. We will pass the lookup function
// into the cache, so it is only called when we don't have a fresh result.
$lookup = function()use($ipAddress):string {
	$jsonString = file_get_contents("https://ipinfo.io/$ipAddress");
	$obj = json_decode($jsonString);
	return $obj->loc;
}

$location = $fileCache->get("lat-lon", $lookup);
echo "Your location is: $location";