Filed under PHP

klickTel Open-API WordPress Plugin

klickTel is a brand of telegate Media. The company is offering free and paid directory assistance information to users of their software, which includes CD-Roms, web portals and mobile applications

Just recently they published an Open API to give people direct access to the data provided by the company. I have started to write a plugin for WordPress to use the data from this API. Using that plugin you can search for directory informations e.g. restaurants or other trades in a certain town or nearby.

The API offers several types of search which will be integrated in the plugin. The first type of search is a meta search, which enables you to look for a “what” in a not specified “where”. “What” can be anything name or trade based, e.g. ‘restaurants’ or just ‘meyer’. “where” is a location information, which can be a zipcode or town name and a street name (or a combination of these).

After searching for ‘restaurants’ in ‘berlin’ I get a list of results:

Those are just an example of what is possible with that kind of API. To get more information you can visit the telegate Blog or register for the API directly.

To get my plugin just visit the page in the WordPress Plugin repository. Feel free to ask any questions here or in the Open-API Google Group.

telegate is hosting an event called ‘Hackathon’ to encourage developers to come and try out the Open-API. You also have the chance to win up to 5.000 €!

Tagged , , , ,

Profiling PHP Code with XDebug and CacheGrind

In my posting about installing a PHP development environment using Ubuntu 10.04 I mentioned the possibility to debug PHP code using XDebug and CacheGrind. Here is a little tutorial on howto use profiling with some free open source tools.

Installation / Configuration

XDebug is a debugging component which can be added as a module to PHP using PECL. To install XDebug (if you havent’t used my tutorial yet) simply use the following code:

1
pecl install xdebug

Now you need to configure XDebug. As a default configuration you should put the following into /etc/php5/conf.d/xdebug.ini:

1
2
3
xdebug.profiler_enable_trigger = 1
xdebug.profiler_enable=0
xdebug.profiler_output_dir = /tmp

The first line enables the profiler by using a trigger. The trigger is a GET/POST parameter called XDEBUG_PROFILE=1 you can use whenever you start a local page via your webbrowser.

The second line enables the profiler by default and would create a profiler output file without a trigger parameter. We don’t want to do that all the time, so the value here is 0. If you want to enable your profiler the whole time, just put a 1 in there.

The third parameter is the path of the directory you want to write your profiler output files to. I’ve inserted /tmp as a default here, but you can change it to any other directory your webserver has write access to.

So an example URL to access a local webpage and create a profile output would be something like this:
http://localhost/index.php?XDEBUG_PROFILE=1

There should be a cachegrind file in your output dir, e.g. cachegrind.out.12345

The number at the end of the filename is the apache pid. The name of the cachegrind file can be configured using another parameter, xdebug.profiler_output_name. A complete documentation of all possibilities can be found here.

Displaying the profile data

There are several tools to analyze the data created by the XDebug profiler. One of these tools is KCachegrind. KCachegrind visualizes traces generated by profiling, including a tree map and a call graph visualization of the calls happening.

As an example: you can analyze how often certain heavy-load methods are called within your application; that way you can find ways to minimize those calls, reduce them to a pure minimum and increase the performance of the application or website.

Alternative visualization tools for different platforms and operating systems are also available, e.g. MacCallGrind für MacOS. A web based solution would be Webgrind, hosted on Google Code.

Tagged , , , , ,

Installing Ubuntu 10.04 Lucid Lynx for PHP development

Lucid-LynxLast year I have written a small how-to for installing an Ubuntu 9.04 work environment as virtualbox environment (though it also works for native systems). Recently I have updated this guide to 10.04 as kind of check list to get a working environment to develop PHP/MySQL applications.

Continue reading

Tagged , , , ,

Google AdWords API 2009 – Overview and First Thoughts

Just recently Google made the new AdWords API 2009 sandbox and documentation available to the public. Some information about it is also in the AdWords API Blog.

I have started to toy around with it. I have written a mayor part of the current AdWords API integration for the company I work for, so it’s best to be prepared for the mayor overhaul Google has done with this new API implementation. Here is a quick overview and some thoughts I have about it.

Authentication

Google seems to unify the use of their APIs with a common login interface: the Account Authentication API. You can make a HTTPS Post Request to the API and use your Google credentials to get an Auth token. This token then will be used to access the functionalities of the API.

I think it is good to unify different kinds of API authentication into a single login service. I just hope that it is stable enough to endure all the load from not just one kind of service but every piece of Google API which will make use of it.

Accessing the Sandbox

I created some example codes (will publish some code in another article soon) to access the Google AdWords Sandbox. At first I had some difficulties because I don’t just use the examples from Google, I created my own kind of library to access the API. That lead to the assumption that I can always use the SOAP end url as namespace – which was wrong because the namespace for the request XML has to be

https://adwords.google.com/api/adwords/cm/v200902

while the actual xml request is being sent to

https://adwords-sandbox.google.com/api/adwords/cm/v200902/....

When sending the wrong namespace the API returns a server error, but no detailed error code about what kind of error occured. I hope Google will improve their error reporting there.

Get & Mutate – the new methods of getting data and manipulating data

Past versions of the AdWords API left the impression of a patchwork API. This time you basically have two functions:

get

Getting data is simple: just build an xml which contains all the parameters you need and send it to the API.

Example:

<get xmlns="https://adwords.google.com/api/adwords/cm/v200902">
 <selector>
  <StatsSelector>
   <campaignIds></campaignIds>
  </StatsSelector>
 </selector>
</get>

This piece of xml tells the API (assuming the header information with the AuthToken, sorry not posting that one here ;) ) to retrieve all the campaigns in the account. You can limit the campaigns by telling it to only include certain campaign IDs (filling the StatsSelecter/campaignIds node with subnodes containing the actual IDs).

mutate

Mutate is the method to create and manipulate data structures in the API.

Example:

<mutate xmlns="https://adwords.google.com/api/adwords/cm/v200902">
 <operations>
  <operator>ADD</operator>
  <operand>
   <name>Test Campaign - 1242726211</name>
   <status>PAUSED</status>
   <budget>
    <period>DAILY</period>
    <amount>
     <currencyCode>EUR</currencyCode>
     <microAmount>1000000</microAmount>
    </amount>
    <deliveryMethod>STANDARD</deliveryMethod>
   </budget>
  </operand>
 </operations>
</mutate>

It tells the API to create a new campaign in the account defined by the client email in the header (again not posted here). The additional OPERATOR tells what kind of operation (ADD, REMOVE, SET). After that all the necessary data for the operation are being added.

Final words (for now)

I think the new API is very clean and straight forward, with a new authentication method. The problems I currently see is the amount of work necessary to migrate applications based on the existing API v13 to the new v2009, but if people are using frameworks like APIlity or one of the other provided libraries, it is safe to assume that new versions will be available soon after the release to make a smooth upgrade.

I am looking forward to work closely with the new API.

Tagged , , , , , ,

8 Good PHP Tools and Libraries to Create and Test Web Applications

Here is a collection of good PHP code libraries I somewhat use to create web based applications. This collection is about PHP only, in another article I will shortly tell you some good Python and Javascript/AJAX libraries.

Zend Framework

The Zend Framework is an object-oriented framework which is focusing on web 2.0 applications. It contains a lot of APIs to webservices like Google, Amazon, Yahoo!, Flickr.

CSV Utilities

PHP CSV Utilities or PCU, is a small, open source PHP library to simplify working with CSV files.

phpExcel

This project provides a set of classes, which allow you to write to and read from different file formats, like Excel 2007, PDF, HTML, … This project is built around Microsoft’s OpenXML standard and PHP.

phpQuery

phpQuery is a server-side, chainable, CSS3 selector driven Document Object Model (DOM) API based on jQuery JavaScript Library.

MC_Google_Visualization

MC_Google_Visualization provides simple support for integrating Google Visualization charts and graphs with your own internal database. It includes a complete parser for the Google Visualization Query Language, giving you the same ease of pivoting and formatting data from your database as is currently possible with Google Spreadsheets.

pChart

pChart is a PHP class oriented framework designed to create aliased charts.

FirePHP

FirePHP enables you to log to your Firebug Console using a simple PHP method call.

SimpleTest

The SimpleTest PHP unit tester is a PHP unit test and web test framework. It has support for SSL, forms, frames, proxies and basic authentication.

If you know any more good PHP libraries and tools, just leave a comment.

Tagged , ,