Updated Storm On Demand API PHP Class
I just wanted to put out that I've updated my API class to use cURL instead of HTTP_REQUEST2 in my initial post.
Although it still utilizes YAML, this is my first move at getting away from third party packages.
Enjoy!
PHP |copy code |?
01 02 <?php
03 /*
04 * Author: Jason Gillman Jr.
05 * Description: This is my attempt at writing a PHP wrapper that will ease Storm API calls with PHP
06 * It will be designed to use the YAML format for talking with the API server.
07 * $api_method is as described in docs (Case matters)
08 * request() method returns an array generated from the API return
09 */
10 class StormAPI
11 {
12 // Let's define attributes
13 private $api_user, $api_pass, $base_url, $api_format, $api_full_uri, $api_request;14 private $api_request_body, $api_method, $api_params, $api_return;15 16 function __construct($api_user, $api_pass, $api_method)17 {
18 $this->api_user = $api_user;19 $this->api_pass = $api_pass;20 $this->api_method = $api_method;21 $this->base_url = 'https://api.stormondemand.com/';22 $this->api_format = 'yaml';23 24 $this->api_full_uri = $this->base_url . $this->api_method . "." .$this->api_format;25 $this->api_request = curl_init($this->api_full_uri); // Instantiate26 curl_setopt($this->api_request, CURLOPT_RETURNTRANSFER, TRUE); // Don't dump directly to output27 curl_setopt($this->api_request, CURLOPT_SSL_VERIFYPEER, FALSE); // Apparently verification doesn't work with the API?28 curl_setopt($this->api_request, CURLOPT_USERPWD, "$this->api_user:$this->api_pass"); // Pass the creds29 }
30 31 function add_param($parameter, $value)32 {
33 $this->api_request_body['params'][$parameter] = $value;34 }
35 36 function request()37 {
38 if(isset($this->api_request_body)) // We have params39 {
40 curl_setopt($this->api_request, CURLOPT_POST, TRUE); //POST method since we'll be feeding params41 curl_setopt($this->api_request, CURLOPT_HTTPHEADER, Array('Content-type: application/yaml')); // Since we'll be using YAML42 curl_setopt($this->api_request, CURLOPT_POSTFIELDS, yaml_emit($this->api_request_body)); // Insert the parameters43 }
44 45 // Now send the request and get the return on investment
46 try47 {
48 return yaml_parse(curl_exec($this->api_request)); // Pull the trigger and get nice pretty arrays of returned data49 }
50 catch (HTTP_Request2_Exception $e)51 {
52 echo 'Error: ' . $e->getMessage();53 }
54 }
55 }
56 ?>
57
Update on 4Apr12 @ 1300EDT
I have updated the class to utilize JSON instead of YAML. Code change was actually pretty straight forward. It is shown below:
TweetPHP |copy code |?
01 02 <?php
03 /*
04 * Author: Jason Gillman Jr.
05 * Description: This is my attempt at writing a PHP wrapper that will ease Storm API calls with PHP
06 * It will be designed to use the YAML format for talking with the API server.
07 * $api_method is as described in docs (Case matters)
08 * request() method returns an array generated from the API return
09 */
10 class StormAPI
11 {
12 // Let's define attributes
13 private $api_user, $api_pass, $base_url, $api_format, $api_full_uri, $api_request;14 private $api_request_body, $api_method, $api_params, $api_return;15 16 function __construct($api_user, $api_pass, $api_method)17 {
18 $this->api_user = $api_user;19 $this->api_pass = $api_pass;20 $this->api_method = $api_method;21 $this->base_url = 'https://api.stormondemand.com/';22 $this->api_format = 'json';23 24 $this->api_full_uri = $this->base_url . $this->api_method . "." .$this->api_format;25 $this->api_request = curl_init($this->api_full_uri); // Instantiate26 curl_setopt($this->api_request, CURLOPT_RETURNTRANSFER, TRUE); // Don't dump directly to output27 curl_setopt($this->api_request, CURLOPT_SSL_VERIFYPEER, FALSE); // Apparently verification doesn't work with the API?28 curl_setopt($this->api_request, CURLOPT_USERPWD, "$this->api_user:$this->api_pass"); // Pass the creds29 }
30 31 function add_param($parameter, $value)32 {
33 $this->api_request_body['params'][$parameter] = $value;34 }
35 36 function request()37 {
38 if(isset($this->api_request_body)) // We have params39 {
40 curl_setopt($this->api_request, CURLOPT_POST, TRUE); //POST method since we'll be feeding params41 curl_setopt($this->api_request, CURLOPT_HTTPHEADER, Array('Content-type: application/json')); // Since we'll be using JSON42 curl_setopt($this->api_request, CURLOPT_POSTFIELDS, json_encode($this->api_request_body)); // Insert the parameters43 }
44 45 // Now send the request and get the return on investment
46 try47 {
48 return json_decode(curl_exec($this->api_request), TRUE); // Pull the trigger and get nice pretty arrays of returned data49 }
50 catch (HTTP_Request2_Exception $e)51 {
52 echo 'Error: ' . $e->getMessage();53 }
54 }
55 }
56 ?>
57
Creating a Gluster Back End on Storm Servers
As described in a previous article, Gluster is a good way to provide centralized storage for a load balanced cluster on Storm.
More below the fold
TweetBig Storage Smart Server
Have you needed a SmartServer with big storage, but didn't want to spend $500 for processor and memory you don't need?
Right now we have a couple i5-760 SmartServers with 4GB of RAM but 1.8TB of storage. These are perfect for those who just need place to store large amounts, whether using the server for serving the content itself, or as a form of network attached storage. These gems are only running for a cool $250. The closest thing that would give you 1.8TB of storage is gonna run you for $500
Want to run a big fat Gluster back end? These are the boxen to use!
And as always, if you have any questions, don't hesitate to give us a call at 800-580-4985.
TweetLoad Balancing with Storm/SmartServers
One of the nice things about our cloud platform (Storm On Demand / Smart Servers) is the ability to easily provision load balancing between nodes. This can be used for a multitude of purposes, from increasing overall performance, to mitigating downtime due to server problems.
However, if you're considering going with a load balanced setup, there are a few key issues to be cognizant of.
More below the fold...
TweetUpgrading from Legacy VPS to Smart VPS
One thing that customers of our Legacy VPS product will have noticed is that CentOS 4 will be End Of Life come February 2012. While this doesn't mean that the server will stop working for them, it means that new patches will not be released, thus potentially exposing the customer to security vulnerabilities as they become known.
While this might cause some initial concern, the solution really isn't that hard. Upgrading to Liquid Web's Smart VPS and migration the data can be a relatively easy process!
TweetSlight hiatus
Well, there is going to bit of a hiatus on future posts here for a while. Well, that or a significantly spaced out time periods between posts.
I am a 25A (that's a Signal Officer) in the Michigan Army National Guard. I am currently down at my Officer Basic Course in Fort Gordon, Georgia for four months.
If during this time you would like to make suggestions for things you'd like to see, please submit a comment!
TweetCopying databases from one cPanel user to another
I was going through some of my tomboy notes and saw some PHP code that I cobbled together for a customer who needed to copy MySQL databases from one cPanel user to another.
I thought that it may be useful to others as well
PHP |copy code |?
01 <?php
02 // cPanel user you are copying data from
03 $from_user = "fromuser";04 // cPanel user you are copying data to
05 $to_user = "touser";06 // Some place to temporarilly story the SQL dump files
07 $dumpdir = "/root/tempdbdump/";08 09 // Add all the databases you need copied over to the array
10 $dumpdb[] = "db1";11 $dumpdb[] = "db2";12 $dumpdb[] = "db3";13 $dumpdb[] = "db4";14 $dumpdb[] = "db5";15 $dumpdb[] = "db6";16 17 foreach($dumpdb as $database)18 {
19 $dumpline = "mysqldump " . $from_user . "_" . $database . " " . $dumpdir . $database .".sql";20 shell_exec($dumpline);21 22 $restoreline = "mysql " $to_user . "_" . $databasename " < " . $dumpdir . $database . ".sql";23 shell_exec($restoreline);24 }
25 ?>
One thing to note is that I got lazy and didn't include code to delete the dump file after use, but that's a relatively simple task.
TweetComplex Setups
One thing that many customers do is going with a more "complex setup" - a setup which involves things such as load balancing, separate database servers, etc. This allows for the mitigation of downtime given the inherent redundancy.
However there are many things that must be considered when looking at these more complex solutions. This includes software architecture, level of experience for the customer in running these setups, etc.
Liquid Web has a page that offers links to pre-configured solutions. For customers that know exactly what they need and how to setup their particular configuration, these links are a great way to quickly order the hardware.
However, for those who aren't quite sure of what they need, or need some assistance with configuring their setup, it is best to contact a Liquid Web sales engineer. The sales engineer will help determine a configuration that will work best for your needs.
For example, do you need your static content to instantaneously become available to all load balanced nodes? Do you upload content through a content management system such as WordPress (such as images or other files)? If so, then you would most likely want some kind of shared storage solution, such as our SAN. Do you manually upload content via FTP/sFTP and only need it pushed through the load balanced pool in non-realtime? Then an rsync solution would work fine from a master. The moral of the story (Aesop really ran a hosting company back in Ancient Greece) is that it is best to consult with one of our sales engineers to determine what solution is best for your hosting needs.
TweetStormOnDemand vs. SmartServers – Which one is right for you?
In a previous article, I presented a comparison between traditional dedicated servers and our cloud based dedicated servers.
However, there are further differences between Liquid Web SmartServers and StormOnDemand Baremetal.
Billing
One key difference between the two cloud services is how billing is broken down.
With Storm, billing is done hourly. SmartServers on the other hand use daily billing.
Bandwidth
Another key difference between the two cloud services is in how bandwidth is handled.
Storm by default using pay per gig pricing - $0.05/GB out. With that said, you can still purchase bandwidth bundles.
SmartVPS servers include 1,000GB In and 1,000GB Out. SmartServers on the other hand include 3,000GB In and 3,000GB Out in the price of the server, with the ability to purchase more bandwidth (again, only for the SmartServers, not SmartVPS).
Backup and Image Pricing
Pricing for backups and user images also differ between the two cloud products.
With Storm, backups are $0.10/GB/Month unless you buy a bundle, compared to SmartServers, which run $0.12/GB/month without a bundle.
For server image storage, Storm hits you for $0.15/GB/month and SmartServers charge $0.25/GB/month
Tweet