Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your profile (name, country/region, and company) is displayed to the public and will accompany any content you post. You may update your IBM account at any time.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Develop apps with Web services and the eBay SDK, Part 3: Develop eBay applications with PHP5 and Web services

Alex Garrett (ljagged@thinkpig.org), Senior Consultant, Isthmus Group, Inc.
After pursuing an undergraduate degree in classics, linguistics, computer science, psychology, and literature, Alex finally settled on a B.S. in philosophy from the University of Wisconsin. His professional career is as checkered as his academic one. He has been the e-commerce architect for a GE Capital company, a lecturer at a University of Wisconsin school, a systems administrator, an acquisitions editor for a small technical publishing company, and a code toad, among other things. Currently, he's a senior consultant with a Madison, WI-based firm and a proud new father.

Summary:  Create applications in PHP5 that interact with eBay through Web services. Almost half of eBay's transactions occur through its Web services platform. In this tutorial, you'll acquire a solid understanding of the mechanics of the eBay XML API and learn how to use the Services_Ebay PHP extension.

View more content in this series

Date:  08 Nov 2005
Level:  Intermediate PDF:  A4 and Letter (135 KB | 35 pages)Get Adobe® Reader®

Activity:  27056 views
Comments:  

Before you start

In June 2004, O'Reilly published a white paper analyzing eBay's Web service deployment. The paper stated that eBay was serving approximately one billion requests each month through its Web service API and that this figure had grown by more than an order of magnitude since 2002. Additionally, one year ago, 40% of all listings on eBay were accomplished through the company's Web services.

I don't know the current figures, but I do know that the developer program is growing by leaps and bounds. eBay continues to refine, adapt, and extend the services it offers through its API. eBay has exposed its entire business model through its API in the hopes that developers will use it to create the next breed of e-commerce applications. This has led to a rich and complex API that requires a fair bit of savvy to master. But eBay works hard to give third-party developers the tools they need to build commercial software offerings.

About this tutorial

This tutorial focuses on developing eBay applications using the XML API with PHP5. The emphasis is on the interface between the application and eBay's Web services, because developing a complete application would be beyond the scope of this tutorial. The tutorial discusses the structure of the request and response XML and the transport mechanism for delivering the requests and retrieving the responses from eBay. It also illustrates in detail how to use the Services_Ebay PHP framework.

The techniques discussed fit equally well in a stand-alone application or a Web application. That may seem strange in a PHP tutorial, because PHP is almost always used for Web applications. However, PHP5 has made inroads toward becoming a general scripting language as well as a Web development language. Developing large Web-based e-commerce applications with PHP offers considerable benefit, but there's also merit in developing small, personal scripts that can run outside a Web server. For example, you might write a script that polls eBay, retrieves all your current auctions, gets the current maximum bid for each one, and e-mails you the total every morning. If this were an Amazon Web services tutorial, the obvious next step would be to have the script automatically order the top items on your wish list, up to the value of the total.


Prerequisites

This tutorial assumes that you're comfortable with programming in PHP and have at least a basic understanding of the object model in PHP5. If you need an introduction to object-oriented (OO) programming in PHP, some resources are listed in the Resources section. Don't be intimidated if you don't have strong OO skills. Although Services_Ebay is built in a very strong OO way, using it doesn't require a lot of OO knowledge.

You should also have a basic understanding of XML; you'll be wrangling a lot of it in this tutorial. You should understand the criteria for a well-formed XML document, be comfortable with the terminology used to describe XML, and so on. As before, check the Resources section if you need a refresher.

Part 2 of the eBay tutorial series explains how to build a book-distribution application with the eBay Java SDK. I highly recommend that you read at least the first half of this tutorial, which provides detailed information about the eBay authentication and authorization mechanism. I'm going to assume you have that knowledge for this tutorial.

In order to execute the examples, you need to have the following software installed:

  • PHP5
  • CURL
  • OpenSSL

Depending on how you built your PHP, you might already have CURL and OpenSSL installed. The easiest way to check is to look at the results of the phpinfo() function:

$ php -r 'phpinfo();' | grep CURL

CURL support => enabled
CURL Information => libcurl/7.13.1 OpenSSL/0.9.7e zlib/1.2.2

Or, you can create a file in a directory accessible to your Web server with the following code:

<?php phpinfo(); ?>

Most of the examples have been developed to run in PHP's CLI mode (as opposed to CGI). This means execution results are echoed to standard out as text instead of being wrapped up in HTML. The benefit of this approach is that you can put the example in a directory and execute it by typing the following:

php -f <filename>

You don't need a running Web server. Running the examples in CGI mode is simply a matter of wrapping the output in HTML. For the examples that display XML, you'll also need to escape the output using the htmlentities function. This is discussed in the appropriate section.

The final prerequisite for this tutorial is a pretty good understanding of the basic patterns of working with the eBay Web services, especially registering your application with eBay and using the authentication and authorization mechanisms. This subject is discussed at length in the Java SDK tutorial. The application registration and authentication and authorization process is platform agnostic. Rather than cover the same material in this tutorial, I recommend that you read the Java tutorial. The first half will make sense to someone with experience in any programming language. The second half discusses implementing Librivore in Java. It may be helpful to skim those sections, if only to see how much simpler PHP users have it.

If you do nothing else, however, at least use the eBay Token Generation Tool (see Resources) to generate a token you can use to execute the code in the examples.


Why PHP?

Telling you why you should use PHP is probably unnecessary. Nonetheless, here are a few reasons why using PHP for developing eBay applications is a Good Thing:

  • PHP is good for rapid application development. It's easy to prototype and incrementally develop applications in PHP. Many of the shortcomings of Java for Rational® Application Developer, such as the static typing and the verbosity of the language, don't exist in PHP.
  • PHP has an enormous number of libraries and extensions. Hundreds of functions are built into the language for developers to use. And the PHP Extension and Application Repository (PEAR), while not CPAN, has lots of extensions that developers can use instead of reimplementing common functionality.
  • PHP is very well documented. The PHP documentation really shines. The manual is structured so that developers can comment on the individual sections with clarifications and code examples. Additionally, many good PHP books let developers get a good understanding of PHP easily. I've listed some of my favorites in the Resources section.
  • PHP is mature. It's been around since 1994, and it's been in constant development and refinement.
  • PHP scales. PHP means Personal Home Page. It was originally designed by Rasmus Lerdorf as a Perl script to make simple dynamic home pages. Now, PHP is being used to build high-availability distributed applications. IBM has partnered with Zend Technologies to build enterprise applications using PHP and Derby or DB2® UDB.

And there's a subjective reason why you should use PHP: I enjoy programming in PHP. If you're reading this tutorial, I'm guessing that you do, too. I hope this tutorial expands your knowledge of the things you can do with PHP and is enjoyable, as well.

1 of 9 | Next

Comments



static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=SOA and Web services, Open source
ArticleID=137246
TutorialTitle=Develop apps with Web services and the eBay SDK, Part 3: Develop eBay applications with PHP5 and Web services
publish-date=11082005
author1-email=ljagged@thinkpig.org
author1-email-cc=