Each account can send a string with extra information to GeoScaling using an XML-RPC call. This extra string can then be accessed from smart subdomain scripts through the $extra_info variable. The string can be mostly anything.
To send the extra information you need to call the function named geoscaling.extra_info. The URL of our XML-RPC server is http://api.geoscaling.com/dns2/xml-rpc/. The function takes 3 arguments:
In the example below we serialized a PHP array and sent it as the string. The code makes use of the XML-RPC for PHP library:
<?PHP include("lib/xmlrpc/xmlrpc.inc"); $client = new xmlrpc_client("http://api.geoscaling.com/dns2/xml-rpc/"); //$client->setdebug(1); $timeout = 5; $payload['datacenter1'] = "43"; $payload['datacenter2'] = "22"; $payload['datacenter3'] = "87"; $msg = new xmlrpcmsg("geoscaling.extra_info", array( php_xmlrpc_encode("USERNAME"), php_xmlrpc_encode("PASSWORD"), php_xmlrpc_encode(serialize($payload)) ) ); $response = $client->send($msg, $timeout); if($response->faultCode()) { print_r($response->faultString()); } else { print_r(php_xmlrpc_decode($response->val)); } echo "\n"; ?>
The XML-RPC function returns one of the following values:
define("OK", 1, true); define("WRONG_PARAMETER_COUNT", 2, true); define("USER_PASS_INCORRECT", 3, true); define("EXTRA_INFO_NOT_STRING", 4, true); define("EXTRA_INFO_TOO_LONG", 5, true);
The following is a user contribution of a combined, closest server + failover + take me offline during deployment. - first the smart subdomain script
/* GeoScaling "smart subdomain script" PURPOSE: 1/ associate url/IP with the physically closest server, monitoring with www.monitis.com reveals minimum of 2x improvement in latency if we do this 2/ take a server out of the list of possible servers if GeoScaling monitoring shows it as down 3/ take a sever out of the list (immediate effect) if we are about to deploy an upgrade of the app software by sending "extra_info" Contributed BY: keitht@sasimedia.net AVAILABLE INFRASTRUCTURE CONSULTING ON 1/ automated build and deploy the N servers in the cloud 2/ Unix or Windows cloud server setup (linode / Rackspace / other) 3/ Techniques for achieving fastest initial page load 4/ No SQL keystore for database replication across cloud servers (Hazelcast + Voldemort + Oracle BDB) 5/ HA / 100 % uptime 6/ Smart browser clients (Flex / GWT), with service calls automatically tied to the fastest responding server (not necessarily the closest) */ $info = unserialize($extra_info); if($uptime['Linode-s1.info']==1 && strcmp($info['linode-s1-offline'],'true') != 0){ $new_server['lat'] = 37.4919627; $new_server['lon'] = -121.93811; $new_server['loc'] = "Fremont, California"; $new_server['ip'] = "1.1.1.1"; //linode-s1 CA $servers[] = $new_server; } if($uptime['rackspace-s1.info']==1 && strcmp($info['rackspace-s1-offline'],'true') != 0){ $new_server['lat'] = 32.7833333; $new_server['lon'] = -96.8; $new_server['loc'] = "Dallas, TX"; $new_server['ip'] = "1.1.1.1"; //rackspace-s1 DALLAS $servers[] = $new_server; } if($uptime['rackspace-s1.info']==1 && strcmp($info['rackspace-s2-offline'],'true') != 0){ $new_server['lat'] = 41.85; $new_server['lon'] = -87.65; $new_server['loc'] = "Chicago, IL"; $new_server['ip'] = "1.1.1.1"; // rackspace-s2 CHICAGO $servers[] = $new_server; } if($uptime['Linode-s2.info']==1 && strcmp($info['linode-s2-offline'],'true') != 0){ $new_server['lat'] = 33.73; $new_server['lon'] = -84.38; $new_server['loc'] = "Atlanta, GA."; $new_server['ip'] = "11.1.1.1"; // linode-s2 ATLANTA $servers[] = $new_server; } $current_lat = $city_info['latitude']; $current_lon = $city_info['longitude']; $minimum_distance = PHP_INT_MAX; $minimum_distance_server_id = 0; for($i=0 ; $i<sizeof($servers); $i++) { $server = $servers[$i]; $distance_to_user = @distance($current_lat, $current_lon, $server['lat'], $server['lon'], "k"); if($distance_to_user<$minimum_distance) { $minimum_distance = $distance_to_user; $minimum_distance_server_id = $i; } } $output[] = array("A", $servers[$minimum_distance_server_id]['ip']); /*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/ /*:: :*/ /*:: this routine calculates the distance between two points (given the :*/ /*:: latitude/longitude of those points). it is being used to calculate :*/ /*:: the distance between two zip codes or postal codes using our :*/ /*:: zipcodeworld(tm) and postalcodeworld(tm) products. :*/ /*:: :*/ /*:: definitions: :*/ /*:: south latitudes are negative, east longitudes are positive :*/ /*:: :*/ /*:: passed to function: :*/ /*:: lat1, lon1 = latitude and longitude of point 1 (in decimal degrees) :*/ /*:: lat2, lon2 = latitude and longitude of point 2 (in decimal degrees) :*/ /*:: unit = the unit you desire for results :*/ /*:: where: 'm' is statute miles :*/ /*:: 'k' is kilometers (default) :*/ /*:: 'n' is nautical miles :*/ /*:: united states zip code/ canadian postal code databases with latitude & :*/ /*:: longitude are available at http://www.zipcodeworld.com :*/ /*:: :*/ /*:: For enquiries, please contact sales@zipcodeworld.com :*/ /*:: :*/ /*:: official web site: http://www.zipcodeworld.com :*/ /*:: :*/ /*:: hexa software development center © all rights reserved 2004 :*/ /*:: :*/ /*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/ //echo distance(32.9697, -96.80322, 29.46786, -98.53506, "m") . " miles<br>"; //echo distance(32.9697, -96.80322, 29.46786, -98.53506, "k") . " kilometers<br>"; //echo distance(32.9697, -96.80322, 29.46786, -98.53506, "n") . " nautical miles<br>"; function distance($lat1, $lon1, $lat2, $lon2, $unit) { $theta = $lon1 - $lon2; $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta)); $dist = acos($dist); $dist = rad2deg($dist); $miles = $dist * 60 * 1.1515; $unit = strtoupper($unit); if ($unit == "K") { return ($miles * 1.609344); } else if ($unit == "N") { return ($miles * 0.8684); } else { return $miles; } }
Here is the php script to send the extra info taking a selected server offline with the url like this http://localhost/offlineServerViaGeoScaling.php?server=linode-s2&offline=false
<?PHP /* GeoScaling "extra_info script" PURPOSE: 1/ send extra_info to take a sever out of the list (immediate effect) if we are about to deploy an upgrade of the app software Contributed BY: keitht@sasimedia.net AVAILABLE INFRASTRUCTURE CONSULTING ON 1/ automated build and deploy the N servers in the cloud 2/ Unix or Windows cloud server setup (linode / Rackspace / other) 3/ Techniques for achieving fastest initial page load 4/ No SQL keystore for database replication across cloud servers (Hazelcast + Voldemort + Oracle BDB) 5/ HA / 100 % uptime 6/ Smart browser clients (Flex / GWT), with service calls automatically tied to the fastest responding server (not necessarily the closest) */ include