Zend Framework

Quickstart web services with SOAP and Zend Framework

(16 votes, average: 4.19 out of 5)
Web services are software systems designed to support interoperable machine-to-machine interaction over a network. Nowadays if you want to connect external systems, you probably want or have to use web services. What I will discuss here is how to get your own SOAP web service up in minutes.

SOAP(Simple Object Access Protocol ) is probably the most used web service protocol today. It relies on XML as its message format, and it uses HTTP for message transmission. The SOAP server uses WSDL(Web Services Description Language ) to describe its services to external clients. WSDL is simply an XML-based language that provides a model for describing Web services.

Back in the old days you had to know a lot about SOAP and WSDL create a web service. Have a look at http://www.php.net/soap to see what I mean. Definitely not very good looking. Luckily Zend Framework has a nice component, Zend_Soap, that handles all the SOAP hard work you would be supposed to do.

So without further ado, here's the code(discussing a Zend Framework component, the code presented here uses the Zend MVC, but you can use it without the Zend MVC):

This is the source code for the controller:
require_once realpath(APPLICATION_PATH .
'/../library/').'/Soaptest.php';


class SoapController extends Zend_Controller_Action
{
//change this to your WSDL URI!
private
$_WSDL_URI="http://192.168.188.128:8081/soap?wsdl";


public function indexAction()
{
$this->_helper->viewRenderer->setNoRender();

if(isset($_GET['wsdl'])) {
//return the WSDL
$this->hadleWSDL();
} else {
//handle SOAP request
$this->handleSOAP();
}
}

private function hadleWSDL() {
$autodiscover = new Zend_Soap_AutoDiscover();
$autodiscover->setClass('Soaptest');
$autodiscover->handle();
}

private function handleSOAP() {
$soap = new Zend_Soap_Server($this->_WSDL_URI);
$soap->setClass('Soaptest');
$soap->handle();
}

public function clientAction() {
$client = new Zend_Soap_Client($this->_WSDL_URI);

$this->view->add_result = $client->math_add(11, 55);
$this->view->not_result = $client->logical_not(true);
$this->view->sort_result = $client->simple_sort(
array("d" => "lemon", "a" => "orange",
"b" => "banana", "c" => "apple"));


}

}

And the code for the Soaptest.php class:

class Soaptest {
/**
* Add method
*
* @param Int $param1
* @param Int $param2
* @return Int
*/
public function math_add($param1, $param2) {
return $param1+$param2;
}

/**
* Logical not method
*
* @param boolean $param1
* @return boolean
*/
public function logical_not($param1) {
return !$param1;
}

/**
* Simple array sort
*
* @param Array $array
* @return Array
*/
public function simple_sort($array) {
asort($array);
return $array;
}

}


You can also download the full project here.

As you can see you don't have to write a lot of code to back up the web service.

Let's discuss the controller first, because there's where the “magic” happens. The index action handles two types of requests: the request for the WSDL, handled by the hadleWSDL() method and the actual SOAP request, handled by the handleSOAP() method.

You can go ahead and try to see how your WSDL looks by accessing http://URL_TO_WEB_SERVICE/soap?wsdl , where URL_TO_WEB_SERVICE is the URL where you have deployed the example. Now imagine that you would have to construct and maintain this yourself, by hand, as old school bearded guys would. Well you don't, because this is handled by Zend_Soap_AutoDiscover which will create the WSDL file for you. The only thing that Zend_Soap_AutoDiscover needs to know is the class you want to use for the web service. Also, because PHP is not strongly typed, you will have to put PHPDoc blocks, because SOAP needs to know what types you are using as parameters and what types you are returning. Have a look here if PHPDoc does not ring a bell .

The SOAP server is handled by the Zend_Soap_Server class, and all it needs is the class you intend to use for the web service, and the URI to your WSDL file. Remember when you checked out how the WSDL file looks? That's exactly the URI you will have to use. In the example you will have to put that into the $_WSDL_URI variable, defined in the SoapController.

That was the SOAP server. Simple, right? Now let's have some tests on the server by implementing a simple SOAP client. The client is handled by the Zend_Soap_Client class that is constructed in the same manner as the server class, it needs just the URI to the WSDL file. After you have constructed the client, you can access the methods defined by the SOAP server in the same way you would access the methods of an object. In the example above you have a simple class, called Soaptest, that defines three very simple methods. Feel free to change the class and test your own methods. While you are playing with the server, you might notice that the WSDL file is cached, so if you change something into the Soaptest.php file, you might not get the expected result. Just delete the cached WSDL file from /tmp/wsdl-* while you do your tests.

Source - http://bogdan-albei.blogspot.com/2009/05/quickstart-web-services-with-soap-and.html

 

Zend plugs PHP into Amazon cloud

Zend Technologies has plugged its PHP web development framework into Amazon's cloud.

On Friday, the company unveiled version 1.8 of its Zend Framework, and for the first time, users can tap directly into the processing and storage resources offered by Amazon Web Services (AWS)

"We're allowing PHP developers to utilize Zend Framework components in order to interact with Amazon's services," Zend Framework project leader and architect Matthew Weier O’Phinney told The Reg. Developers can access Amazon's Simple Storage Service (S3) directly from PHP, as if it were a remote file system, adding and removing files via scripts. Plus, they can seamlessly upload, start, and stop server instances on Amazon's Elastic Compute Cloud (EC2).

"So, you can scale your web application when you need to. If you have a traffic spike, you get a couple more instances running on EC2."

Zend's new EC2 service was driven by a project contributor working for a business already using the framework in tandem with AWS. And O’Phinney said that countless other developers have requested such tight integration with Amazon's fluffy web-based infrastructure.

"We all want to write and deploy the next Twitter or the next Facebook, and the only way you're going to be able to do that is if you're able to off-load some of your computing power from your own servers," O’Phinney said. "Amazon is a great way to get started with that, right off the bat."

Could Amazon handle the next Twitter? You have to wonder.

Zend 1.8 also offers rapid application development (RAD), a means of quickly prototyping web apps. With the framework's RAD-happy Zend_Tool component, developers can build data and process models on the fly, mapping out a web app to suit their particular needs.

The Zend Framework - free and open-source - is available by-itself or as part of the Zend Server, the company's web application server. Zend Server offers a kind of data caching back-end, for off-loading processing duties from the app itself, and as O’Phinney pointed out, this could potentially be used in tandem with Amazon EC2 as well. ®

   

Zend Framework 1.8.1 Released

(1 vote, average: 5.00 out of 5)

The Zend Framework team is happy to announce the immediate availability of Zend Framework 1.8.1, the first maintenance release in the 1.8 series. You can download it via our downloads page; Use the CDN link for fast downloads, or scroll down the page for direct downloads of the 1.8.1 packages from the ZF servers.

1.8.0 was released only 13 days ago, but we already have logged 68 resolved issues in that timeframe! We appreciate everyone who has taken the time to log bugs, documentation issues -- even issues with the Quick Start! -- as well as those who have given generously of their time to help resolve them.

One important bugfix that should be noted is that a glitch in packaging of 1.8.0 meant that the Dojo version shipped with it was from the Dojo 1.2 branch -- and not the 1.3 branch as reported in the changelogs. The packaging script has been corrected, and the source build within the full ZF distribution now correctly includes Dojo 1.3.

Other prominent changes include:

  • Zend_Loader::registerAutoload() now proxies to Zend_Loader_Autoloader, and marks the instance as a fallback autoloader. This will ensure equivalent functionality, and reduces the number of deprecation notices emitted to one.
  • Many bugfixes and improvements to Zend_Application.
  • Addition of module generation capabilities to Zend_Tool
  • Addition of strong object typing capabilities to Zend_Amf
  • Many more manual translations!

For a full list of resolved issues, please visit the ZF issue tracker.

   

Zend Framework 1.8.0 Released

(1 vote, average: 5.00 out of 5)
 

Zend Framework 1.8.0 Released

I'm pleased to announce the Zend Framework 1.8.0 release, the first in our 1.8 series of releases. This release marks the culmination of several long-standing projects, as well as a formalization of many of our recommended practices.

There are two major stories in this release: first, the addition of several components designed to provide and promote Rapid Application Development; second, two offerings that make using Zend Framework in the cloud easier.

Rapid Application Development

1.8.0 marks the first public release of Zend_Tool. At its simplest, Zend_Tool provides a command-line script that can be used to ease many common project-related tasks: setting up the project tree, adding controllers, actions (and related view scripts), model classes, etc. More advanced users can create their own tool providers that can then be directly invoked from that script -- or even create their own RPC endpoints so as to expose the tooling on the web or via a web service.

In a related vein, 1.8 also introduces Zend_Application, which provides a standard and object oriented method for bootstrapping applications. Bootstraps may define their own initialization resources, or draw upon some common plugins to do their work. Additionally, resources may be bootstrapped individually, allowing you to utilize a common bootstrap with multiple gateway scripts tailored for different tasks.

One dependency of Zend_Application is Zend_Loader_Autoloader. Zend_Loader_Autoloader is a replacement for Zend_Loader::autoload(), and solves many of the issues users have reported with that solution. Additionally, it provides the ability to manage a stack of namespaced autoloaders, working around some minor issues of the SPL's autoloader as well as providing opportunistic matching of namespace prefixes to match your classes quickly. A subcomponent, Zend_Loader_Autoloader_Resource provides a simple mechanism for mapping classes to the filesystem when the directory structure may not exactly correspond to the class name. By using an autoloader by default, you can help keep your code more performant as well as leave class resolution out of your code -- greatly epediting application development.

Note: the Zend Framework Quick Start has been updated to use Zend_Tool and Zend_Application. It's an excellent introduction to these components as well as Zend Framework's MVC in general.

Cloud Computing

Web 2.0 applications have many demands not seen in traditional web applications. One of these is the need for distributed storage, and another is the need to scale horizontally on demand as traffic to your site spikes.

Amazon has provided solutions to both of these problems for several years now with its Simple Storage Service (S3) and Elastic Compute Cloud (EC2), respectively.

Amazon S3 provides web services developers may use to store and retrieve data. The service is distributed, and thus highly scalable, reliable, and fast. Zend_Service_Amazon_S3 provides an object oriented approach to the service, as well as a PHP streams wrapper -- both designed to make working with S3 from your PHP applications a simple matter.

Amazon EC2 provides a web service to allow launching and managing server instances within Amazon's data centers. These server instances may be used at any time for any length of time -- allowing you to scale your site only when you need to handle extra traffic, or run your services entirely from the EC2 platform.

Other Contributions

The number of community contributions and bug fixes for 1.8.0 has been phenomenal. Below is a list of the primary feature additions for the release.

  • Zend_Tool, contributed by Ralph Schindler
  • Zend_Application, contributed by Ben Scholzen and Matthew Weier O'Phinney
  • Zend_Loader_Autoloader and Zend_Loader_Autoloader_Resource, contributed by Matthew Weier O'Phinney
  • Zend_Navigation, contributed by Robin Skoglund
  • Zend_CodeGenerator, by Ralph Schindler
  • Zend_Reflection, Ralph Schindler and Matthew Weier O'Phinne
  • Zend Server backend for Zend_Cache, contributed by Alexander Veremyev
  • Zend_Service_Amazon_Ec2, contributed by Jon Whitcraft
  • Zend_Service_Amazon_S3, Justin Plock and Stas Malyshev
  • Incorporated Dojo 1.3
  • Added support for arbitrary Dojo Dijits via view helpers
  • Zend_Filter_Encrypt, contributed by Thomas Weidner
  • Zend_Filter_Decrypt, contributed by Thomas Weidner
  • Zend_Filter_LocalizedToNormalized and _NormalizedToLocalized, contributed by Thomas Weidner
  • Support for file upload progress support in Zend_File_Transfer, contributed by Thomas Weidner
  • Translation-aware routes, contributed by Ben Scholzen
  • Route chaining capabilities, contributed by Ben Scholzen
  • Zend_Json expression support, contributed by Benjamin Eberlei and Oscar Reales
  • Zend_Http_Client_Adapter_Curl, contributed by Benjamin Eberlei
  • SOAP input and output header support, contributed by Alexander Veremyev
  • Support for keyword field search using query strings, contributed by Alexander Veremyev
  • Support for searching across multiple indexes in Zend_Search_Lucene, contributed by Alexander Veremyev
  • Significant improvements for Zend_Search_Lucene search result match highlighting capabilities, contributed by Alexander Veremyev
  • Support for page scaling, shifting and skewing in Zend_Pdf, contributed by Alexander Veremyev
  • Zend_Tag_Cloud, contributed by Ben Scholzen
  • Locale support in Zend_Validate_Int and Zend_Validate_Float, contributed by Thomas Weidner
  • Phonecode support in Zend_Locale, contributed by Thomas Weidner
  • Zend_Validate_Db_RecordExists and _RecordNotExists, contributed by Ryan Mauger
  • Zend_Validate_Iban, contributed by Thomas Weidner
  • Zend_Validate_File_WordCount, contributed by Thomas Weidner
   

Zend Server Released !

Following months of intensive beta testing, both Zend Server and Zend Server Community Edition (CE) have been released! We would like to take this opportunity to extend a big "thank you" to the thousands of beta testers who were kind enough to test-drive the beta products and provide invaluable feedback. We would also like to thank all those who blogged, tweeted, posted and answered questions on the forum!

Haven't yet heard of Zend Server?

Zend Server is a Web application server – a complete PHP stack that provides the performance, reliability and security required for running business-critical applications including:

  • Application monitoring for early problem detection
  • Zend Studio integration for fast root cause analysis
  • Caching and bytecode acceleration for optimal performance
  • Technical support, software updates and hot fixes
  • Integrated installers that are native to the OS (RPM/DEB/MSI)

Please check out our website to test drive Zend Server, download the free Zend Server Community Edition or learn more about Zend Server.

From the CTO's Desk - by Zeev Suraski

PHP is Winning

Last month I was given the honor of opening the PHP conference in Quebec. My keynote was titled "Why PHP Wins". Several weeks prior to the conference, I stayed at a small, old hotel in Buenos Aires. The clerk who checked me in examined my credit card, looked up at me and curiously asked if I was the Zeev Suraski from PHP. It turned out he's using PHP to implement a social network for his neighborhood!

It's no secret that PHP has become extremely popular. It's the most pervasive Web development language in the world, spanning tens of millions of Web sites and millions of developers. It's not just quantity either - the quality is there too, with some of the largest Web sites in the world - such as Facebook and Wikipedia - using it to deliver their critical and enormously-loaded applications.

So we've established that PHP is doing well and that its ecosystem is thriving, what now? Do we sit back and enjoy the spoils? Not quite. With all the building blocks in place, we feel it's time to move it up a notch and take a broader look at the PHP application lifecycle. If we want to continue to increase the maturity of the PHP platform, we need to deliver a full solution that spans across all lifecycle stages. We need both great IDEs and robust Web Application Servers, and we need to close the loop between developers and system administrators during application deployment and when problems crop up in production. Doing so will increase the success of PHP projects and deliver massive productivity gains that are key in today's down economy.

A key ingredient in this vision is the new Zend Server that we have just announced. While the first thing you'd notice about it is that it makes PHP a breeze to install, its value goes much beyond a supported, easily-installable PHP application stack. It provides a true enterprise-grade environment for building and running PHP applications. It helps developers and system administrators maintain consistency across development machines and production servers - even when using different operating systems in development and production. It is tightly integrated with Zend Studio for closed-loop debugging, and works incredibly well on Windows (good news for anyone using Windows to develop or run PHP!). There's obviously more to Zend Server than there's room here to write about - check it out!

PHP INDUSTRY NEWS

Microsoft Web PI: What does it mean for PHP?

Make Web, Not War.

This is the title of Microsoft's presentation announcing the release of Microsoft Web Platform, a collection of Microsoft tools and technologies for developing and running Web applications. This new bundle from Microsoft is interesting as it allows users to download PHP and even install a bunch of PHP applications, such as Drupal and phpBB.

It seems like Microsoft has finally come to terms with the dominance of PHP in the Web application space. This is the first time Microsoft has presented PHP as a viable alternative to .NET.

As Andi Gutmans wrote in his blog a couple of weeks ago, "we, at Zend, have been working closely with Microsoft since 2006 to make sure PHP applications running on Windows get the same reliability and performance they get on Linux". The newly released Zend Server is, in many ways, a culmination of these efforts. It is the best performing PHP stack for Windows. It provides native MSI support, MSI-based hot fixes, native IIS support, SQL Server for PHP, FastCGI, and more.

Data Caching with Zend Server

"Cache, Cache, and Cache" is what most experts would reply when asked what are the most significant methods to speed up a PHP application. There are lots of optimizations that could be done to PHP code that would make it run faster, but the most effective method to speed up PHP execution is to simply execute less, and one of the best ways to achieve that is through caching.

Zend Server provides several caching-related features, including Optimizer+ for byte-code caching, full HTTP response caching using Zend Page Cache, and for precision-guided caching of PHP variables, data and even output elements, the Zend Data Cache. This whitepaper will demonstrate how to apply the Zend Data Cache API in order to speed up an existing PHP-based blogging application. While doing so, different aspects of caching in general and specifically with Zend Server will be covered, including: shared memory vs. disk based storage, programmatic cache invalidation and namespacing of cached items. An overview of different caching strategies and a discussion of when each strategy should be used is also reviewed.

Zend Server Data Caching whitepaper

PHP in the Trenches - by Ed Kietlinski

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. It's also the time me and my wife take our classic car out for a spin. It's fun to drive with the top down to shake off the 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)...
   

JPAGE_CURRENT_OF_TOTAL

Feedback Form