Rackspace Cloud SDK for PHP getting started Rackspace Cloud SDK for PHP is an SDK that helps PHP developers develop applications based on OpenStack and Rackspace Cloud (including public and private clouds) more conveniently. This SDK includes the following components: 1. php-opencloud language binding (under the "lib" Directory) 2. document (in the "docs/" Directory) 3. sample Code (in the "samples/" Directory) how to install the SDK can be obtained through the Rackspace GitHub source. Http://github.com/rackspace/php-opencloudget the most easily available release version (stable version) code: 1. click Tags link 2. select the latest version, and click the next step. find the file you just downloaded in your download directory. Remember the directory location and you will use it later. In this example, you will write code to create two 1 GB ECs instances running Ubuntu13.04. You need a text editor to edit the following code. The complete code is as follows: <? Php require ('/path/to/lib/php-opencloud.php'); define ('image _ UBUNTU ', '9922a7c7-5a42-4a56-bc6a-93f857ae2346'); define ('flavor _ 1gb ', '3'); // create a certificate $ connection = new \ OpenCloud \ Rackspace (RACKSPACE_US, array ('username' => 'username ', 'Password' => 'Password'); // connect to compute service $ compute = $ connection-> Compute ('cloudserversopenstack', 'ord '); // find the image $ Image = $ compute-> image (IMAGE_UBUNTU); // obtain f Lavor object $ flavor = $ compute-> Flavor (FLAVOR_1GB); // create a server for ($ I = 0; $ I <2; $ I ++) {$ server = $ compute-> Server (); // get a blank server $ resp = $ server-> Create (array ('name' => sprintf ('server-% d', $ I ), 'image' => $ image, 'flavor' => $ flavor); // check if ($ resp-> HttpStatus ()> 204) die ("Errorbuilding server. response is ". $ resp-> HttpBody (); // display the root password printf ("Server [% s] is building. root password is [% S] \ n ", $ server-> Name (), $ server-> adminPass);} Understand this program <? Php require ('/path/to/lib/php-opencloud.php'); <? Php is essential to all PHP code (PHP often sneak into HTML ). The Require () statement contains the ** php-opencloud ** library. You need to edit this field to specify the exact path of the php-opencloud.php file (under the lib/folder of the directory you just downloaded ). Define ('image _ UBUNTU ', '9922a7c7-5a42-4a56-bc6a-93f857ae2346'); define ('flavor _ 1gb', '3'); the two constants define the image id of the Ubuntu13.04 IMAGE, and 1 GB flavor. To use different flavor or images, use novaclient CLI to query available values in Rackspace Control Panle. // Establish our credentials $ connection = new \ OpenCloud \ Rackspace (RACKSPACE_US, array ('username' => 'username', 'Password' => 'Password ')); in this way, a '$ connection' object is created using' \ OpenCloud \ Rackspace 'connector. This object requires two parameters: 1. authentication endpoint URL ('rackspace _ us' is a useful constant provided by ** php-opencloud ). 2. an array containing your username and password. Edit the value of ''username''' to map your USERNAME and PASSWORD. // Now, connect to compute service $ compute = $ connection-> Compute ('cloudserversopenstack', 'ord '); create a "Compute" class, connection to the specified service strength in ORD region (in this case, the service is named "cloudServersOpenStack"), Compute () method returns a new connection to the service. // First, find the image $ image = $ compute-> Image (IMAGE_UBUNTU); // get a flavor object $ flavor = $ compute-> Flavor (FLAVOR_1GB ); this is the other two factory methods that return an "Image" object and a "Flavor" object respectively. // Create the server for ($ I = 0; $ I <2; $ I ++) {$ server = $ compute-> Server (); // get a blank server $ resp = $ server-> Create (array ('name' => sprintf ('server-% d', $ I ), 'image' => $ image, 'flavor' => $ flavor); // check for errors if ($ resp-> HttpStatus ()> 204) die ("Errorbuilding server. response is ". $ resp-> HttpBody (); // display the root password printf ("Server [% s] is building. root password is [% s] \ n ", $ se Rver-> Name (), $ server-> adminPass);} This actually creates a server. A new empty Server object is created from the "$ compute" service using the "Server ()" method. Finally, the "Server" object calls the "Create" method and must pass an attribute array as the parameter. 'Name', 'image', and 'flavor' are required to create a new server.