ThinkPHP /dev/blog - PHPContinuous Integration und Cruise Control im Projekteinsatz -> Vortrag@Mayflower-München (8.2.2010, 22:35 UTC)
Am kommenden Donnerstag, den 11.02.2010 findet wieder ein öffentlicher Vortrag im Mayflower Büro in München statt (Mannhardtstraße 6, S-Bahn Isartor).
Beginn ist um 18:00 Uhr, Thema des Vortrags ist "Continuous Integration und Cruise Control im Projekteinsatz"

Sebastian Springer zeigt wie man Continuous Integration in PHP-basierten Entwicklungsprozessen einsetzen kann, insbesondere mit dem CruiseControl Framework.

Die "Donnerstags-Vorträge" werden sowohl in München als auch in Würzburg gehalten. Bei Interesse einfach das Blog beobachten, um auf dem Laufenden zu bleiben!
Wir freuen uns auf viele Teilnehmer!

Link
TechPortalCoding Is The Easy Part (8.2.2010, 08:00 UTC)

Writing code is easy. Instantiating objects, calling methods, memorising functions (or using the documentation instead); these are all trivial tasks that we have all taken time to study and practise. But engineering software is so much more than coding. As a software engineer you take on several roles throughout the software development life cycle. Let us take a look at some key roles that developers play during the software development life cycle, some problems you can run into, and how to solve them.

The Planner

The secret to planning any successful project is good estimates or no deadlines. Since the latter never happens, you need to take on the former and become a planner. This is the most challenging step of software development and the most critical. A lot of software engineers would like to think that planning is not useful to a project. The concept of ‘the software will be done when I finish it is very appealing, allowing you to continue developing with no outside interference. However in practice that is not feasible for most businesses. In order to run a project, a business needs to have a plan of what will be done, including a timeline which relates to the budget, and feel confident that in the end they will have a working deliverable. This means you must bite the bullet and make a plan before you begin to code.

A common claim is that planning doesn’t work because its impossible to predict the future, however this is only true to an extent. It is entirely possible to plan how to write a particular piece of software and how long it will take. It is also perfectly feasible to stick to this plan and deliver on time. The problems arise when an unknown is encountered during the course of the project, throwing you off schedule. This is totally normal but you cannot prevent, predict or stop this from happening. The only thing you can do is change your reaction to it. Flag the event as soon as it appears and tell the client about it. Be prepared to tell them the solution to the problem at the same time and the new delivery date if it will change.

Making accurate estimates is entirely possible if you take your time and really think about what you need to do. Break the project up into smaller pieces of work, called features or stories. Do not simply accept your gut instinct of how long it will take to do something. Think about each step you will need to take in building each piece of the software. There could well be a step you didn’t consider in your initial estimate. This hidden work will cost you a lot of time over the course of the project. Once you’ve estimated how long it will take to write the code, you should add to your estimate the time it will take to complete all the other work including architecture, testing and documentation. The easiest way to do this is to figure out a scale which you can calculate against. For example, if you spend 7 hours coding something, it will take you 1 hour to document it. This scale will vary depending on your project or team.

The Architect

Architecting software is actually part of the planning process. It is a very lengthy part involving a lot of research, thought and work; thus it becomes our second role in developing software. In order to build software, you need to have a plan. And in order to have a plan, you need to know what you will build. If you do not give a developer some general guidelines on how to write their code, they will improvise and do it in their own way. If you begin to code up front without taking time to design the system, you’ll find yourself re-doing a lot of the work in refactoring later on. This is not good for the stability of the product and can cause problems or bottlenecks during the development process. You may end up repeating the same work over and over again if you have not taken a good look beforehand to determine what to do.

All too often when building a system we overlook the importance of the system infrastructure. This is traditionally a systems administration task, but as a team lead or member of the planning team, you are responsible for determining what is needed and getting it implemented so your software can be used. You need to allow time to determine the system infrastructure and implement at least a development environment before starting the project. If this infrastructure is not in place beforehand, you’ll have a lot of time wasted by developers trying to set up and maintain their own environments.

Truncated by Planet PHP, read more at the original (another 10962 bytes)

Link
Venkat Raman DonTroubleshoot – My PHP script is timing out (8.2.2010, 01:23 UTC)

I hear a lot about the problem where web server (IIS) throws an error saying that PHP script has timed out in our forums. Let’s try to understand the reason behind this. I will be using a Windows 7 Enterprise machine (having IIS 7.5) to explain this but this should be applicable to Windows 2008/Windows Vista too. The same can be told true for Windows 2003/Windows XP with some difference like IIS stores FastCGI configuration in fcgiext.ini file rather than application meta-base. However the concept should be exactly similar.

Let me now summarize some of the IIS FastCGI settings and PHP INI configuration directive to ensure that everyone is on the same page and which are most important for this discussion.

Two important FastCGI settings:

  • ActivityTimeout – This is the number of seconds that the FastCGI handler waits for I/O activity from a process before it is terminated. At some place you will also find this as being documented as number of seconds PHP-CGI process can run without communicating to IIS.
  • RequestTimeout – This is the maximum amount of time in seconds that a FastCGI process is allowed to handle a request before it is terminated.
  • Important PHP INI directive for this discussion:

  • max_execution_time – This is the maximum time in seconds a script is allowed to run before it is terminated by parser. Details can be seen at http://www.php.net/manual/en/info.configuration.php#ini.max-execution-time.
  • All the above three impacts your script execution time. Ideally you will have the value of RequestTimeout greater than or equal to ActivityTimeout. Well this is not a hard rule but going by meaning of these two timeouts it makes sense to do this. Assume you are uploading a file of size ‘X’ MB and it takes 500 second to upload it (assuming PHP is configured properly to allow upload of files and so the size of ‘X’ MB is also allowed) and you have below value for the two timeouts:

    ActivityTimeout=501

    RequestTimeout=400

    This configuration will result into request timeout while uploading the file. The reason is that though an I/O operation (in this case file upload) is allowed for 501 seconds which is perfectly fine for this case, request time out is less than 501 (and is at 400) and so FastCGI will encounter a request timeout. Remember this will be done by the web server (IIS here) and not PHP. So setting the value of RequestTimeout higher than ActivityTimeout makes more sense.

    However assume your max_execution_time is set to 300 seconds and you are running a PHP script which executes for time more than 300 seconds and FastCGI timeout settings are same as above. This time PHP will terminate itself.

    This implies that (assuming you have RequestTimeout set to a value higher than ActivityTimeout) you script will run maximum for time in seconds which is configured for max_execution_time or RequestTimeout whichever is less.

    This should help you configuring the PHP script to run for a longer period of time.

    Some Frequently asked question

    • I am changing the fastcgi.ini file or php.ini file but settings are not getting effected on XP/2k3 or I am changing applicationhost.config or php.ini on a IIS7 machine and changes are not getting effected.

    Please recycle the application pool or restart the server to make the FastCGI/PHP process read the new settings. If you are using latest FastCGI and you do not want to restart the application and want changes to be picked up on it’s own you can as well use the feature called ‘Monitor Changes to File’. Details about this can be found at http://blogs.iis.net/ksingla/archive/2009/01/22/improvements-to-fastcgi-in-iis-7-5.aspx for IIS7.5 and at http://learn.iis.net/page.aspx/248/configure-the-fastcgi-extension-for-iis-60/ for IIS6.0. For information regarding if this feature is supported on your configuration or not please refer to blog post at

    Truncated by Planet PHP, read more at the original (another 7922 bytes)

Link
Benjamin EberleiResources for a PHP and Hudson CI Integration (7.2.2010, 11:25 UTC)

Yesterday I finally had the time to setup my first continuous integration environment. Possible solutions for CI are phpUnderControl, Hudson or Arbit. Although phpUnderControl is the most wide-spread, but from I heard complex to setup/maintain, solution supposedly a hack and Arbit just in an early Alpha I decided to give Hudson a shoot. Another reason for this decision, I heard it has a simple plugin architecture and is easy to install and use. Additionally Hudson is easily integrated into Netbeans and Redmine, and I use both tools regularly in development.

My motivation to dive into CI is easily explained. I just never felt it was necessary to add a continuous integration enviroment to my projects, since I had one or two simple bash scripts that did the job. In general this is rather annoying, because they mostly only run PHPUnit and have to be done using a cronjob or manually, without any real process of notification. Additionally you have no way to navigate the test-results, code-coverage and no history of the last builds. For projects like Doctrine 2 we have the additional requirement to support 4 different database platforms, i.e. 4 different PHPUnit configurations. Currently that is solved by me using a Bash script that iterates over the configuration file names and invokes PHPUnit.

There are already some awesome sources how to get Hudson and PHP working. I'll list them here:

All those guides are already awesome and I would recommend choosing one of those to install Hudson, I think i can't add anything new to those. I have used Sebastians Howto, however i also like the third one. David Luhmans guide adds lots of details that are important to get the different parts of a build process to work.

Now what these tutorials all do is that they use a bash command to execute the build process or specifiy an Ant Build file. However there is also a Phing Build process plugin for Hudson that allows to specify the build.xml targets to execute in the process. From the "Available Plugins" list you can choose the "Phing plugin".

After installation you have to configure the Phing install. The Phing Plugin Wiki Page shows how to do this. You have to go to "Manage Hudson" => "Configure System" and look for Phing. There you find the dialog to configure your phing installations.

In the context of choosing a build script for your project you can now choose "Phing" instead of Ant:

You can enter the targets to build, for example on my local Hudson instance I only execute "test" for Doctrine 2, since I am not interested in the building and deployment onto the PEAR channel at this development stage.

From inside Netbeans you can then start builds by pointing to the Hudson instance. See this tutorial by one of the Hudson + Netbeans Developers. You can then start all the builds from inside Netbeans and be notified of the success or failure.

Link
Rafael DohmsHipHop for PHP: First look (6.2.2010, 14:50 UTC)

Just this tuesday Facebook announced a ambitious project called “HipHop for PHP”, if you missed it general opinion says you have been coding PHP in a cave. As I write this review no code has been posted yet, but Facebook has made a great move to open source the project so we can all get our hands on it, use it and contribute to it. So since the code is not out there yet, this is literally a first impression article based on the presentation made by Facebook and various posts from core PHP developers who got a first look at the technology before the release.

What is it?

To be blunt, its a PHP to C++ code transformer (compiler). But that does not make justice to it, so let’s look deeper. To those of you that know PHP intimately you understand the process behind running PHP, it is thus:

PHP Code –interpreter–> OP CODE –Zend Engine–> Machine Language

Generally caching solutions store OP Code and reuse it instead of running the interpreter for every request. What HipHop does is completely different and surprised quite a few people who decided to guess what they were doing. On a general view this is the process (simplified):

PHP Code –parser–> C++ Code –g++–> Compiled binary

Historically PHP has always been executed on the Zend Engine, heart of PHP that has been around since PHP3, but what this solution does is that the Zend Engine has been recoded into the HipHop Runtime Engine, which instead of OP Code takes in C++ code that has been generated based on the original PHP code.

Why HipHop?

Its a well known fact that running code in C is faster then running PHP code, for obvious reasons, its very common for large applications in PHP to port part of its codebase to C and package it into an extension, such as Yahoo and even PHP projects like Doctrine have done so, performance of simple operations can increase in as much as hundreds percent, depending on load and usage.

This is the premise for Facebook’s project, they have long contributed to APC and PHP to get more performance out of their code, but with the increased load of billions of pages served it was not enough, they decided then to solve the problem. One of the options on the table was move on to another language all together, but this is where PHP shines, Facebook declared that PHP is simply a great solution because they can easily and rapidly get new programers up to status and developing in PHP due to its simplicity, that and the fact that their code base consists of million+ lines of code made them decide that this was not a solution, thus HipHop started.

How does it work?

The idea is that PHP code can be divided into “mundane” and “magic” code. Being mundane code basic operations that are directly mapped to C++ functions. This code if converted to C++ can be executed with much higher performance, while the magic code, which is the really complex code to be converted would run at equal or slightly lower speeds. This is the point that determines if you application can benefit from this, is it more mundane then magic?

If your answer is yes, then you may want to look into it. The converter does a lot of processing identifying dependencies, doing static analysis and other operations to get the basic code, it then has to take care of the problematic issue, Typing. PHP is a weakly typed language, meaning variables can juggle their types to and from various types. In the backend of this Zend Engine implements the ZVAL type, which basically stores anything. For the C++ code the new variables are typed so the parser needs to do all this in its Type Interface. The project’s lead Engineer, Haiting Zhao, stated that one of the solutions was to map ZVALs to the C++ Variant type whenever its impossible to determine a specific type (failed type inference), or when typecasting occurs in the process of the script. After all this analysis code is finally generated.

Thus this code is compiled against the HipHop Runtime, which as I said works like the Zend Engine and works now with specialized types instead of the abstract types in the Zend Engine. Binary in hand this can now be run straight from the command line, or interfacing with a web server as its compatible with the libevent library. Currently Facebook also wrote a very simple web server to interface with its compiled code replacing its Apache on calls to this code (as far as information goes, they proxy PHP traffic to this server and leave resources going through Apache).

The good and th

Truncated by Planet PHP, read more at the original (another 6982 bytes)

Link
Tobias SchlittBottom K items from a stream (6.2.2010, 11:10 UTC)
I recently had the problem that I wanted to retrieve the smallest items from a stream of data. When talking about a stream here, I refer to a data set that I do not want to load into memory completely, since it has quite a few elements. The best way to process such data is a stream approach, where you work always on a single item at a time, iteratively, without loading the full data set.In my special case, I had a database with 140,000 records. The processing of these records could not happen in the DB, since I needed to create vectors from text and perform calculation on these. Basically, I needed to check each vectors distance to a reference vector and keep only the k closest ones.So, what is a good approach to solve such a task? I decided to implement a custom data structure based on a max heap to solve the problem. In this article, I present the solution and compare it to two different other approaches in terms of a small benchmark.
Link
Raphael StoltUtilizing Twitter lists with Zend_Service_Twitter (5.2.2010, 01:05 UTC)
Twitter lists with the Zend FrameworkSeveral months ago Twitter added the list feature to it's public API. While debating some use cases for an event registration application I stumbled upon an interesting feature, which adds participants automatically to a Twitter list upon registration. This way registered and interested users can discover like-minded individuals and get in touch prior to any pre-social event activities. This post will show how this feature can be implemented by utilizing the Zend_Service_Twitter component, and how it then can be used in a Zend Framework based application.

Implementing the common list features

Looking at the three relevant parts of the Twitter list API some common features emerged and had to be supported to get the feature out of the door. These are namely the creation, deletion of new lists and the addition, removal of list members (i.e. event participants). Since the current Twitter component doesn't support these list operations out of the box it was time to put that develeoper hat on and get loose; which was actually a joy due to the elegance of the extended Zend_Service_Twitter component laying all the groundwork.

A non-feature-complete implementation is shown in the next code listing and can alternatively be pulled from GitHub. Currently it only supports the above stated common operations plus the ability to get the lists of a Twitter account and it's associated members; but feel free to fork it or even turn it into an official proposal.
<?php

require_once 'Zend/Service/Twitter.php';
require_once 'Zend/Service/Twitter/Exception.php';

class Recordshelf_Service_Twitter_List extends Zend_Service_Twitter
{
const LIST_MEMBER_LIMIT = 500;
const MAX_LIST_NAME_LENGTH = 25;
const MAX_LIST_DESCRIPTION_LENGTH = 100;

/**
* Initializes the service and adds the list to the method types
* of the parent service class.
*
* @param string $username The Twitter account name.
* @param string $password The Twitter account password.
* @see Zend_Service_Twitter::_methodTypes
*/
public function __construct($username = null, $password = null)
{
parent::__construct($username, $password);
$this->_methodTypes[] = 'list';
}
/**
* Creates a list associated to the current user.
*
* @param string $listname The listname to create.
* @param array $options The options to set whilst creating the list.
* Allows to set the list creation mode (public|private)
* and the list description.
* @return Zend_Rest_Client_Result
* @throws Zend_Service_Twitter_Exception
*/
public function create($listname, array $options = array())
{
$this->_init();

if ($this->_existsListAlready($listname)) {
$exceptionMessage = 'List with name %s exists already';
$exceptionMessage = sprintf($exceptionMessage, $listname);
throw new Zend_Service_Twitter_Exception($exceptionMessage);
}

$_options = array('name' => $this->_validListname($listname));
foreach ($options as $key => $value) {
switch (strtolower($key)) {
case 'mode':
$_options['mode'] = $this->_validMode($value);
break;
case 'description':
$_options['description'] = $this->_validDescription($value);
break;
default:
break;
}
}
$path = '/1/%s/lists.xml';
$path = sprintf($path, $this->getUsername());

$response = $this->_post($path, $_options);
return new Zend_Rest_Client_Result($response->getBody());
}
/**
* Deletes an owned list of the current user.
*
* @param string $listname The listname to delete.
* @return Zend_Rest_Client_Result
* @throws Zen

Truncated by Planet PHP, read more at the original (another 14678 bytes)

Link
Matthew Weier O'PhinneyCreating Re-Usable Zend_Application Resource Plugins (4.2.2010, 19:55 UTC)

In my last article, I wrote about how to get started with Zend_Application, including some information about how to write resource methods, as well as listing available resource plugins. What happens when you need a re-usable resource for which there is no existing plugin shipped? Why, write your own, of course!

All plugins in Zend Framework follow a common pattern. Basically, you group plugins under a common directory, with a common class prefix, and then notify the pluggable class of their location.

For this post, let's consider that you may want a resource plugin to do the following:

  • Set the view doctype
  • Set the default page title and title separator

Continue reading "Creating Re-Usable Zend_Application Resource Plugins"
Link
PHP 10.0 Blogzf book review (4.2.2010, 19:48 UTC)

As I mentioned before, I got the book Zend Framework 1.8 Web Application Development for review. It took me a bit more time than I though to do this (one of the reasons will become clear soon) but here it finally comes.

I think it is a great book for somebody who is somewhat acquainted with Zend Framework and wants to get really good at working with it. It covers a lot of ground, so if you never worked with ZF before you might be a bit overwhelmed by the amount of stuff going on (then again, maybe I am underestimating you :) ), so you may want either skip some detail to return to it later when the need arises or have a run through a very basic tutorial for getting to know how the framework works before. The book itself has the basic startup section but I feel for a complete newbie it still might be a bit tough to keep up with the amount of the material in the book. That of course will come handy later when you got the basics figured out.

I personally am a big fan of learning by example and I think one line of code is often worth a hundred words, so I was really pleased that this book is based on building a complete application and comes with full application code to accompany it. The application is a storefront with an admin interface, so it covers most of the common tasks in a typical PHP application.
While it means that on the road there were certain decisions to be taken, and certain ways of doing things will be chosen over certain others, the author clearly identifies the decision points and explains the reasons – i.e. why certain things go to a model and not controller, why this extension point and not that one is used, etc. ZF has a very rich set of features, so there’s no single “right way” to do all things – but the book certainly shows you one of the ways to reach the complete and nicely structured application.

I actually took a bit of an experiment – as I was at the time building some ZF-based application, I decided to use the book as a first reference for any question that I needed with the app. I am pleased to report that the book indeed proved very helpful and I was able to find most of the advanced topics – like the use of ACLs, interactions between forms, views and decorators, modifying the behavior of the standard ZF classes, etc. – answered in the book and demonstrated in the code. The author successfully avoided the temptation to quote the manual extensively and instead picks up where the manual leaves off – i.e. how does one use stuff that the manual describes in practice.

The book also covers – albeit somewhat lightly – the topic that is neglected by so many other ZF books – namely testing. It shows how to setup the test environment and how to execute some basic application tests. Ideally, I would like the topic of tests to be much more prominent and featured as something parallel to development and not something you do after (though I know that’s how it rally happens many times ;) ) – but I know there’s only so much you can put into one book :)

Summarily, I think it is a good book to have if you do or about to do serious ZF development.

Tagged: book, PHP, zend framework
Link
Danne LundqvistDynamically change z-index on Google Maps markers (4.2.2010, 15:12 UTC)

As many have noticed Google Maps API does not include a setIndex() method on the marker. You can set the z-index when adding a marker to the map. But it is not possible to change this afterwards.

I didn’t find a good solution to the problem when searching and had to resort to my own, hacking away on Google Maps. As I was feeling really good about myself when I had it working really well I just remembered that Google Maps Javascript API V3 has been released in Google Labs… And of course there it was. The Marker class has a new method, setZIndex(zIndex:number).

Well, version 3 of the API is still only released by Google Labs which is “home to developer products that are still in their formative stages“. So for anyone not inclined to use version 3 just yet, I’ll write down how I did it here.

As I use JQuery in this particular project the example is also using JQuery. If used in production I suggest using try/catch wherever appropriate as the solution depends on a specific dom structure.

I have the below HTML which is the container for the Google map.

<div id="indexmap"></div>

The map is created as below (you’ll have to add the lat/lng variable values yourselves.

var map = new GMap2($('#indexamp'));
var point = new GLatLng(lat, lng);
map.setCenter(point, zoom);

This, as most know, creates the actual map. Then it is time to add the markers. In my case I have a list of locations with the latitude/longitude in the actual html. JQuery helps me loop over these locations and dynamically add markers in the correct spots. This HTML looks like below. Note how each definition list have an id no with “mm_” as prefix. (Never mind any objections you have on having many definition lists like this… Never mind that these coordinates are fiction…)

<dl id="mm_0">
  <dt>...</dt>
  <dd>
    <span class="lat">61.333</span><span class="lng">31.1324</span>
    Random text
  </dd>
</dl>
<dl id="mm_1">
  <dt>...</dt>
  <dd>
    <span class="lat">61.333</span><span class="lng">31.1324</span>
    Random text
  </dd>
</dl>

What I want is the markers to be highlighted with a different icon every time I hover over a definition list element (dl). However, both have the same coordinates and one of the markers will be hidden behind the other.

So to prepare we need to make sure the actual images in the Google generated map can be connected to these defintion list id:s. The Google map have many different layers on top of each other. One layer contain the foreground images, another the shadows, mouse map definitions and so on. Each of these layers (normal div elements) have their own z-index.

In these different layers the images used have their own z-index. However, the z-index for the marker foreground image is the same as for the transparent clickable marker image. This makes it possible to use the transparent image z-index to restore the foreground image z-index. This is important as not to confuse the user when he later click on a marker…

So let’s loop over these images and give them appropriate id values as well as put the markers on the map. (No - Google does not give them id’s). This is, stripped to the bare essentials, the complete code with some comments.

// Create the map
var map = new GMap2($('#indexamp'));
var point = new GLatLng(lat, lng);
map.setCenter(point, zoom);

// Loop over the definition lists picking up coordinates
var n = 0;
$('dl').each(function() {
        var lat = parseFloat($('span.lat', this).text());
        var lng = parseFloat($('span.lng', this).text());
        var point = new GLatLng(lat, lng);

        // Create the marker with custom images
        var markerIcon = new GIcon(G_DEFAULT_ICON);
        markerIcon.image = 'marker_default.png';
        markerIcon.iconSize = new GSize(23, 30);
        markerIcon.shadow = "marker_shadow.png";
        markerIcon.shadowSize = new GSize(50, 30);
        markerIcon.iconAnchor = new GPoint(11, 29);
        markerIcon.infoWindowAnchor = new GPoint(11, 14);

        var marker = new GMarker(point, {icon: markerIcon});

        // Change the foreground image when hovering over a definition list
        // Note that the actual id's have not been created yet.
        var no = this.id.substring(3); // Exclude the prefix
        $(this).hover(
                function() {
                        marker.setImage('marker_selected.png');
                        // Bring this image to foreground
                        $('#mf_' + no)[0].style.zIndex = 1;
                },

Truncated by Planet PHP, read more at the original (another 933 bytes)

Link
LinksRSS 0.92   RDF 1.
Atom Feed   100% Popoon
PHP5 powered   PEAR
ButtonsPlanet PHP   Planet PHP
Planet PHP