Wednesday, April 1, 2009

Taking Zend Server for a Spin (part 1)

April in my neck of the woods is when the weather starts to get nice and Spring is in full bloom, its also the time my wife and I take our classic car out for a spin. Its fun to drive with the top down to shake off winter blues and drive somewhere new. Well I've been doing a lot of that at work too testing the new Zend Server and seeing what's under the hood (not just the Zend Engine 2, but all the other things that make the new server go).

If you've missed all the news and announcements about Zend Server, take a look at Andi's blog, it has some real good posts and an insiders look at the Windows and Linux versions.

In my blog this week I'd like to take Zend Server for a spin, if you want to follow along you will need to install it first, and then activate all features by installing a trial license, your first screen should look all green on the right side like the figure above. If not, you may not have licensed your trial copy, click here for instructions, or if you originally decided not to active some features, its easy to reactivate.

Next let's setup some PHP apps to work with, setting up the preinstalled Zend Framework demos are easy to do. If IIS is your web server I recommend using IIS7 that supports the apache rewrite rules module and just copy the demo zend framework directory into the www root.

If youre using apache web server you can also copy the "demo" directory from the Zend Framework install, to your htdocs web root. To find out where the demo's are located, you can do a browser page search in the following PHPINFO screen, it can be found in ZendServer Admin menu Monitor>PHP Info and then do a search in the page for the word ZendFramework. That will list out the entire path downto the library subdirectory, just go up one level and you will see the demo folder.

If you copyed it in the right place it should all work now, your first Zend Framework demo should display now in the browser, http://localhost/Demo/Gdata/YouTubeVideoBrowser and it should look like this screen (BTW you can click on any screen shot to zoom in and get a bigger view of it):

This Youtube demo is using the Zend Framework GDATA modules, there are many other examples that interface into Google apps like calendar, spreadsheet, photos, health, books, docs, and blogger. For full details of the ZF API for Google apps and all source is provided on how to do it in PHP. This would be a great way to build some of those web apps that I wrote about from Genentech last week.

There are quite a few web services examples, to run the Amazon book example type the following,
http://localhost/Demo/WebServices/Amazon/amazon-search.php there is also a UPC lookup example http://localhost/Demo/WebServices/Protocols/xmlrpc-upc-lookup.php

If you try to run the flickr demo you will probably only see a white screen in the browser come up.
http://localhost/Demo/WebServices/Flickr/flickr-search.php Is there something wrong with the demo or code bug? To help figure this out, let's go back to our Zend Server monitor screen and look at the latest error at the top of the screen, I highlighted it in grey here.Click on this first event to get even more details about the problem we are having. Click the ERROR DATA tab in the middle of the screen and we can see exactly why the problem is happening, its an INVALID API KEY.
So let us click Show File in Zend Server if you have that up and running and enter a valid key in the file flickr-search.php, you should register for your own key, its free at flickr and can be found here. There are a lot of problems scenarios like this that come up in real production and testing environments, that makes Zend Server ideal to track down quickly. Many times just looking at all the data collected is enough to figure out the problem like in this case, other times the applicaiton and problem is more complex and we would need to troubleshoot it with the Zend remote debugger or profiler. I'll have some more examples that will show how this is used, but for now let us just edit the file in Zend Studio and enter the API key in the code.

And save it, to test it goto http://localhost/Demo/WebServices/Flickr/flickr-search.php and if your key is valid you'll get a screen full of pictures instead of a blank window as before.
Next let us look at a feed demo, its a typical thing you would find in any content management system or PHP portal like Joomla, Drupal, or Dekiwiki. http://localhost/Demo/Zend/Feeds/consume-feed.php If you go back to Zend Server you will notice a new event at the top "SEVERE SLOW REQUEST EXECUTION", that's a bottleneck identified by Zend Server. On my laptop it sometime takes more then 2sec to execute this feed, I should know because on my firefox I have also installed a plugin to show me the rendering time of a page (FF plugin is called LORI)

There's another useful utility called the Zend Controller preinstalled in the bin subdirectory of ZendServer that can help us measure performance. Let's paste the feed URL into the utility and run a quick test to see how many requests per sec it can handle. Looks like only 1.1 requests/sec on my laptop, see figure below:

Now lets use Zend Server's page level caching to improve the performance of this feed as you can imagine this is a common problem in many portals and wiki's. I go back to Zend Server Admin, menu>Rules Management>Caching and will add a new caching rule.

I called my rule "FASTFEED" I filled in the URL to cache the output "http://localhost/Demo/Zend/Feeds/consume-feed.php" and then set the rule to cache the output for 360 sec and saved my script. Be sure to RESTART PHP after saving rule for it to take effect. Now I re-run my performance benchmark in Zend Controller, here's a screen shot of both the feed and performance test:

Notice in the Zend Controller I now have 3.75 times more requests per sec, and in Firefox the page speed went from 2-0.9/sec to 0.24/sec a dramatic speed improvement. Since this is a RSS feed, the timings vary wildly at different times during the day but this example is representative of realworld situations. Also note the Zend Controller measures first byte returned so tools like Apache Benchmark, JMETER and LOADRUNNER are good tools for further benchmarking.

So download Zend Server and take it for a spin, if you also use open source projects like SugarCRM for example, many will detect the installation of Zend Server and its data caching and will perform significantly faster automatically. In an upcoming article, I'll take some of those for a spin too and list out all the ones that I have tested. For more news on Zend Server release, click here.

The band I've been listening to the most while taking things for a spin this month is
Kings of Leon

1 comment:

Edward Kietlinski said...

If you're using apache web server you can also create a server alias instead of copying folder, you will need to locate your httpd.conf file, if you type http://localhost/server-info and scroll to the bottom of the page, it will show you the path of it in bold. Just use an editor and edit the httpd.conf file and add the following apache alias to the bottom. You need to also replace "PATHTOZENDFRAMEWORK" below with your real path to the demos, and it can be found in ZendServer Admin menu Monitor>PHP Info and then do a search in the page for the word ZendFramework. Copy the entire path from beginning to just the ..\ZendFramework (do not include the \library at the end of the path)
# Alias for Zend Framework Demos location
Options All
Order deny,allow
Allow from all

# END ALIAS for Demos

Restart your apache webserver and if it all worked your first Zend Framework demo should display now in the browser, http://localhost/Demo/Gdata/YouTubeVideoBrowser and it should look like the 2nd screen above.