Differences

This shows you the differences between the selected revision and the current version of the page.

sending_extra_information_to_dns2_with_the_xml-rpc_api 2015/01/24 21:38 sending_extra_information_to_dns2_with_the_xml-rpc_api 2015/01/30 00:42 current
Line 1: Line 1:
Each account can send a string with extra information to GeoScaling using an [[wp>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. Each account can send a string with extra information to GeoScaling using an [[wp>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://xml-rpc.geoscaling.com/. The function takes 3 arguments:+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:
  * username - string - your username   * username - string - your username
Line 14: Line 14:
include("lib/xmlrpc/xmlrpc.inc"); include("lib/xmlrpc/xmlrpc.inc");
-$client = new xmlrpc_client("http://xml-rpc.geoscaling.com/");+$client = new xmlrpc_client("http://api.geoscaling.com/dns2/xml-rpc/");
//$client->setdebug(1); //$client->setdebug(1);
Line 55: Line 55:
define("EXTRA_INFO_NOT_STRING", 4, true); define("EXTRA_INFO_NOT_STRING", 4, true);
define("EXTRA_INFO_TOO_LONG", 5, true); define("EXTRA_INFO_TOO_LONG", 5, true);
 +</code>
 +
 +The following is a user contribution of a combined, closest server + failover + take me offline during deployment.
 +- first the smart subdomain script
 +<code php>
 +/*
 +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;
 +      }
 +}
 +</code>
 +
 +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
 +<code php>
 +<?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("lib/xmlrpc.inc");
 +
 +$client = new xmlrpc_client("http://api.geoscaling.com/dns2/xml-rpc/");
 +//$client->setdebug(1);
 +
 +$timeout = 5;
 +echo  $_GET['server'] . '-offline'  . "=" .  $_GET['offline'] . "\n";
 +
 +
 +$payload[$_GET['server'] . '-offline'] = $_GET['offline'];
 +
 +// set online any servers not specified in arguments
 +if ($_GET['server'] != 'linodes1')
 +    $payload['linode-s1-offline'] = 'false';
 +
 +if ($_GET['server'] != 'yrs1')
 +    $payload['rackspace-s1-offline'] = 'false';
 +
 +if ($_GET['server'] != 'yyyy-s2')
 +    $payload['rackspace-s2-offline'] = 'false';
 +
 +if ($_GET['server'] != 'xxxx-s2')
 +    $payload['linode-s2-offline'] = 'false';
 +
 +
 +$msg = new xmlrpcmsg("geoscaling.extra_info",
 +        array(
 +                php_xmlrpc_encode("keith198"),
 +                php_xmlrpc_encode("daddy1"),
 +                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";
 +
 +?>
 +</code>
 +
 +The following contributed code makes an XML-RPC call from Java. It uses the redstone XML-RPC library: http://xmlrpc.sourceforge.net/
 +
 +<code java>
 +  // test geoscaling api via restlet
 +        String url="http://api.geoscaling.com/dns2/xml-rpc/";
 +        XmlRpcClient client = null;
 +        try {
 +            client = new XmlRpcClient(url,false);
 +            Object token = client.invoke( "geoscaling.extra_info", new Object[] { "USER", "PASS","s1-offline=true" } );
 +            int x = 1+2;
 +          } catch (MalformedURLException e) {
 +            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
 +        } catch (XmlRpcFault xmlRpcFault) {
 +            xmlRpcFault.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
 +        }
</code> </code>
 
sending_extra_information_to_dns2_with_the_xml-rpc_api.txt · Last modified: 2015/01/30 00:42 by mstenz
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki