Zend Server 5.1 Web API

Leave a comment

This weekend we soft launched the Zend Server 5.1 update.  So soft, in fact, that I didn’t even know it was launched.  But I did know it was coming.  Most of the improvements were either bug fixes or performance improvements.  Some of the performance improvements have actually been pretty significant, particularly under load.

But we did add a new feature that works both with Zend Server and Zend Server Cluster Manager.  This release for Cluster Manager is actually really nice.  I have a video demo that I recorded last week on scaling web applications that I could not have pulled off without the cluster manager.  One of the things that a scalable app does is “find” resources.  This can be application level, or in this case, infrastructure level, as I was using load balancing.  I had an error that I could not find because I did not know which server the logic ran on.  People often add loads of logging to store all of that information so they can go and retrace the steps that caused it.  I just said “screw it” and installed the Cluster Manager.  It took one request to reproduce it and I had all of the information I needed.

Seriously, if you have more than 2 or 3 servers and have enough budget to cover some basic employee benefits you NEED to look at Cluster Manager.  I knew the selling points of Cluster Manager before this, but I was sold on it when I needed it to do its thing when I recorded that video.

But I have digressed a little.

The new feature we added in both Zend Server and Zend Server Cluster Manager 5.1 was a new web API.  It allows you to programmatically access a subset of Zend Server’s provisioning features.  Some of them are available only to the Cluster Manager, but others are available for the regular version of Zend Server, i.e. the “single instance” version.

The feature list is as follows.

  • Get System Info
  • Get Server Status
  • Add Server
  • Remove Server
  • Disable Server
  • Enable Server
  • Restart PHP
  • Configuration Export
  • Configuration Import

The web API is RESTful and has an authentication method that calculates a request signature based off of a secret key that you can generate with either full access or read-only rights in the Zend Server GUI.

But I personally found that while the API was quite useful I could see that people would end up building their own adapters or scripting it in a way that would make it look like spaghetti.

So I wrote my own API that plugs in to the web API and makes your life easier.  I have included it as part of my Job Queue API up on GitHub and it requires PHP 5.3

There are a few simple steps to using it.

  1. Instantiate an API key object
  2. Instantiate a method object that represents the method you wish to call
  3. Instantiate the manager which controls the communication
  4. Call the method by passing it into the controller
  5. Read the response (which will either be raw data, a response object of a defined type (com\zend\api\response\*) or an array of response objects).

It’s really easy to use.  Take, for example, this code that will restart PHP on an individual server.

That’s it.  Or this code to export the current configuration.

Those are examples of API calls that work on the regular version of Zend Server.  Here are a few that work with Cluster Manager.

Say you want to add a server to your Zend Server cluster.  All you need to do is put this code in a provisioning script that runs on the node.

Done with the server and you want to remove it from the cluster (including graceful handling of session data)?

As you can see with the new web API you now have the ability to automate a bunch of the more brainless tasks that you’d rather let a machine take care of.

Get Zend Server (trial available)

Leave a Reply

Your email address will not be published. Required fields are marked *