News

COURSE: Zend Framework: Fundamentals

The Zend Framework: Fundamentals course is designed for experienced PHP programmers who want to learn to combine ZF concepts and structural elements to utilize the full power of this software development kit for PHP 5 applications.

The course helps you to learn by doing. Each discussion of related components is presented with examples of how best to utilize them in your applications, Hands-on exercises and the mini-projects you develop during the course reinforce the concepts you have learned. The online Zend Training Center allows participants to develop code during the course with your instructor able to see and coach your progress.

This course is offered online – with a live instructor – for 18 hours (9 – 2 hour sessions).

Author:
Source: Zend Events


  • Share/Bookmark

by News Robot on August 29, 2010 in News, No Comments »
tags: ,

Database Replication Adapter for Zend Framework Applications

Last updated: 21 Feb, 2010

Database replication is an option that allows the content of one database to be replicated to another database or databases, providing a mechanism to scale out the database. Scaling out the database allows more activities to be processed and more users to access the database by running multiple copies of the databases on different machines.

The problem with monolithic database designs is that they don’t establish an infrastructure that allows for rapid changes in business requirements. Here is where database replication comes into play. Replication can be used effectively for many different purposes, such as separating data entry and reporting, distributing load across servers, providing high availability, etc.

Zf_Orm_DataSource is a Zend Framework Replication Adapter class flexible enough to support the most commonly used replication scenarios:

Single-Master Replication

In the simplest replication scenario, the master copy of directory data is held in a single read-write replica on one server called the supplier server. The supplier server also maintains changelog for this replica. On another server, called the consumer server, there can be multiple read-only replicas.

Configuration array:

$config = array(
    'adapter'        => 'Pdo_Mysql',
    'driver_options' => array(PDO::ATTR_TIMEOUT=>5),
    'username'       => 'root',
    'password'       => 'root',
    'dbname'         => 'test',
    'master_servers' => 1,
    'servers'        => array(
        array('host' => 'db.master-1.com'),
        array('host' => 'db.slave-1.com'),
        array('host' => 'db.slave-2.com')
    )
);

// or ...

$config = array(
    'adapter'        => 'Pdo_Mysql',
    'driver_options' => array(PDO::ATTR_TIMEOUT=>5),
    'dbname'         => 'test',
    'master_servers' => 1,
    'servers'        => array(
        array('host' => 'db.master-1.com', 'username' => 'user1', 'password'=>'pass1'),
        array('host' => 'db.slave-1.com', 'username' => 'user2', 'password' => 'pass2'),
        array('host' => 'db.slave-2.com', 'username' => 'user3', 'password' => 'pass3')
    )
);

In the setup above, all writes will go to the master connection and all reads will be randomly distributed across the available slaves.

Multi-Master Replication

This type of configuration can work with any number of consumer servers. Each consumer server holds a read-only replica. The consumers can receive updates from all the suppliers. The consumers also have referrals defined for all the suppliers to forward any update requests that the consumers receive.

$config = array(
    'adapter'        => 'Pdo_Mysql',
    'driver_options' => array(PDO::ATTR_TIMEOUT=>5),
    'username'       => 'root',
    'password'       => 'root',
    'dbname'         => 'test',
    'master_servers' => 2,
    'master_read'    => true,
    'servers'        => array(
        array('host' => 'db.master-1.com'),
        array('host' => 'db.master-2.com')
    )
);

Using a distributed memory caching system

Database connections are expensive and it’s very inefficient for an application to try to connect to a server that is down or not responding. A distributed memory caching system can help alleviate this problem by keeping a list of all the failed connections in memory, sharing that information across multiple servers and allowing the application to access it before attempting to open a connection.

To enable this option, you have to pass an instance of the Memcached adapter class:

class Bootstrap extends Zend_Application_Bootstrap_Base
{
    protected function _initCache()
    {
        ...
    }

    protected function _initDatabase()
    {
        $config = include APPLICATION_PATH . '/config/database.php';
        $cache = $this->getResource('cache');
        $dataSource = new Zf_Orm_DataSource($config, $cache, 'cache_tag');
        Zend_Registry::set('dataSource', $dataSource);
    }
}

And here is a short example of how the Replication Adapter might be used in a ZF application:

class TestDao
{
    public function fetchAll()
    {
        $db = Zend_Registry::get('dataSource')->getConnection('slave');
        $query = $db->select()->from('test');
        return $db->fetchAll($query);
    }

    public function insert($data)
    {
        $db = Zend_Registry::get('dataSource')->getConnection('master');
        $db->insert('test', $data);
        return $db->lastInsertId();
    }
}

Source Code:
http://fedecarg.com/repositories/show/replicationadapter

Posted in Databases, Frameworks, Open-source, Programming

Author: Federico


  • Share/Bookmark

by News Robot on August 28, 2010 in News, No Comments »
tags: ,

Easily Format and Output Currency Values with Zend Framework

Currency can be a pain. Different currency symbols, different formats, rounding, etc, etc. Zend makes it easy!

At it’s simplest, you can output formatted currency values as follows:

$currency = new Zend_Currency();
//prints 00.00 if user is in US
echo $currency->toCurrency(1000);

But Zend_Currency can do so much more than that. For example, it is compatible with Zend’s localization components, meaning that you can setup a Zend_Locale object once in your application, and Zend_Currency sees it and automatically performs the necessary formatting and conversions. For example, suppose you have an early running resource in your Zend MVC application that determines the appropriate locale for the application. In your bootstrap or resource file, you would have something like this:

//Detect user locale automatically
$locale = new Zend_Locale();

//Or pass a locale to use that locale
//$locale = new Zend_Locale('en_US');

//Save to registry
Zend_Registry::set('Zend_Locale', $locale);

Once you save the Zend_Locale object to the registry (using the key ‘Zend_Locale‘), all locale aware components of the Zend Framework will automatically use that locale for any conversions and translations.

The defaults will be sufficient for most uses, but many options are available to help you customize how Zend_Currency operates. For a full listing of options, please see the Zend Framework reference guide.

Calculating with Currencies

Zend_Currency allows you to do many calculation and comparisons with currencies, such as addition, subtraction, multiply, divide, modulo, and equality operations such as equals, greater than and less than.

For example, suppose we have a currency object with a starting value of 00. The easiest way to perform operations on our object is to use Zend_Currency‘s built in functions, like so:

$currency = new Zend_Currency(array('value' => 1000));

//Add 0 to the currency
$currency->add(100);

//Subtract 0 from the currency
$currency->sub(100);

In this way, you can easily perform arithmetic operations on your currency objects, without the need for first retrieving the value in the currency object, then performing the operation on the value, which would then be a number rather than a Zend_Currency object, which would remove all the handy formatting and conversion possibilities.

Exchange Rates

Zend Framework does not supply a way to convert currencies out of the box, but it does make quite easy to do so. Basically, you need to write a simple class that will talk to a conversion rate web service and then return the exchange rate to Zend_Currency, which handles all the math itself. For more information, please see the Zend Framework reference guide on exchange rates.

Performance

For most websites, performance will not be much of an issue as far as the Zend Framework is concerned. On websites that get a decent amount of traffic, however, the complicated nature of the Zend Framework can lead to decreased performance. Luckily, the authors of ZF have thoughtfully made many components caching enabled, meaning you can tell them to use a cache and they will automatically speed themselves up. Zend_Currency can use a cache object to increase performance. To use caching in Zend_Currency, simple set a cache object like so:

Zend_Currency::setCache($cache);

NOTE: the $cache object must be an instance of Zend_Cache. For more information on how to create cache objects with ZF, see How to use Memcache with the Zend Framework.

Author: nick
Source: ZendCoding


  • Share/Bookmark

by News Robot on August 28, 2010 in News, No Comments »
tags:

PHPBenelux conference 2010 wrapup

This past weekend, Belgium was buzzing PHP all the way. PHPBenelux organized the first annual international PHP conference in Belgium and it can be called a true success. Attendees and speakers coming from all parts of the world made this event a true international conference and I was truly happy to be a part of it, this time as member of the organization.
Preparation
The months, weeks and certainly the days prior to the conference were hectic, stressful and sometimes energy draining. With lots of things that still needed to be done last minute, we have learned that we still have lots of room to improve ourselves for future events. But, as it is common to PHP development, we met our deadlines and saw everything was running smoothly.
Airport and train station runs
The conference had a few international speakers on the list, for who we had to ensure a smooth ride to the conference hotel. Stefan Koopmanschap picked up Cal Evans at Schiphol. Thijs Feryn went down to Antwerp Central Station to pick up Fabien Potencier, and had to do this 3 times returning each time without Fabien (read his blog article about what happend). I myself went to Brussels International Airport to pick up David Zülke and Rowan Merewood traveling together with Ben Waine.


Speaker’s dinner and pre-conference social
As is custom to events like this, we organized as speaker’s dinner where we invited our speakers and sponsors to participate in this socializing event where everyone has the opportunity to get to know each other, discuss topics and exchange ideas. We headed out to Da Giovanni, an Italian restaurant in the center of Antwerp that is known for it’s overwhelming tacky design. Red-white blocked cloths everywhere: the shirts of the waiters, the tables and lamps. We had a decent meal and a very good laugh.
Following the dinner we also organized a pre-conference social in De Vagant, one of Antwerp’s most known Jenever locations. This was open for everyone that was in the area and could make it to the place. But tiredness and pre-conference jitters had this social ended well before midnight.
The conference
Saturday was the big day, and what a day it was ! Sponsors arrived well in time to set up their booths and at about 8:30am the first attendees were coming in. Since it had snowed during the night, most attendees were a bit late so we started the sessions with a delay of 30 minutes (by lunch time we were already back on schedule).
After a short introduction by Stefan Koopmanschap, Derick Rethans officially opened the conference with his keynote talk “The PHP Universe”, which was well accepted by the audience (See reviews on http://joind.in/1240). The following talks followed right after and filled the most of the conference.
Remote presentation
Due to bad weather, Zend‘s speaker Eric Ritchie couldn’t make it to the conference, but by using WebEx we were able to have him present his talk “Generating dynamic PDFs using Zend Framework and JavaBridge” (http://joind.in/1268) from his office as though he was standing in the room. Although it was a bit tough to set up, I have to say it was successful fix for Zend, WebEx and us.
One downside of this approach is that Eric didn’t had the chance to interact with the attendees himself during or after his keynote and as shown in the comments on joind.in there were still a few questions that the attendees wanted to clarify with Eric. So, in a technical perspective it can be called a success, but for the conference spirit it has a downside.
Closing Keynote
My personal mentor and dear friend Cal Evans was given the floor to present his closing keynote “Open Teams” (http://joind.in/1251) which was unlike the other talks not a technical subject, but non-the-less a very valuable view on how managers and developers can improve the way they operate. Unfortunately I missed this talk, but I’m looking forward seeing it on an other occasion. You can contact Cal and invite him to give this talk for the managers in your company, so your company can become “Company Awesome” everyone wants to work for.
Ibuildings Conference Social
The people of Ibuildings were really kind to sponsor the after-social event, held in the exhibition hall. Besides drinks and very delicious food, our other sponsors had some goodies to give away and so people walked away with an iPhone and Zend Studio licenses, a ticket for PHPBenelux Conference 2011, a ticket for PHPUK 2010, Windows 7 licenses, a netbook (provided by Nocus) and of course elePHPants. So a big applause to the winners and of course our sponsors for providing these awesome prizes.
Sponsors
This great conference wasn’t possible without the help of our sponsors, and we all thank them for making this first conference the best start of 2010. Thank you !!!
PHP is hot !
Apparently PHP is hot, hotter then ever. At the conference, a lot of people not only attended the great sessions, but they were also looking for new PHP developers to join their teams. And they were not just giving you a great job, they even offered some real nice goodies when you signed up:
If you’re a company and you’re looking for PHP Rock stars, see how you can persuade them to at least talk to you. Make sure you have seen the slides of Cal Evans‘s talk about “Open Teams“, cause if you can offer this, you do have the advantage !
PHPBenelux Team
This conference succeeded because of the never-failing, passionate help and support by the whole PHPBenelux team. I have worked in many teams already, but I have to say that working with these guys on a remote basis (all using Skype, Google docs and e-mail as main communication and collaboration tools) worked very well (as to emphasize what Cal Evans stated in his “Open Teams” talk) and everyone was there to see the result.
Teamies, thanks a lot for this wonderful experience and I’m looking forward doing the things we do best: community relations, meetings and events ! You guys rock !!!
PHPBenelux team by @phpcodemonkey
Conclusion
This was the first conference that I not only attended, but was actually involved behind the scenes. It was a great experience and I have now more respect to organizers of bigger conferences now that we know what kind of challenges they have to overcome.
Read what others had to say about our conference:
I had a blast and I hope you all enjoyed it. See you all next year at the PHPBenelux Conference 2011, and let us know how to improve ourselves for next years’ conference at joind.in !!!

Author:


  • Share/Bookmark

by News Robot on August 28, 2010 in News, No Comments »
tags: ,

The Semi-Official Zend Framework Pear Channel

Pear Channel?

For the past few months, the ZF team has been playing with the idea of releasing ZF from a PEAR channel. Over the past 2 years, we have seen a few channels distributing ZF that have pop up here and there.. so that lead us to believe there is an itch that needs scratching.

The compelling reason against a PEAR channel is that, with ZF, there is nothing to “install”. Just pop ZF in your include_path and off you go. You could obtain ZF from SVN via export, checkout or externals tag.. or you could download from the website. A PEAR channel (until recently), didn’t make enough sense because copying files from one location to another was all it would be doing.

ZF Grows beyond Component Library

That is … until ZF 1.8 (coming soon to developers near you). With 1.8, Zend_Tool will be going into production. I’ve chatted (#zftalk.dev@freenode) about it, I’ve spoke about it (#zendcon08), and I’ve tweeted about it in recent months. But for those that don’t know, I can sum Zend_Tool up in 3 major aspects of functionality:

  • Zend_Tool_Framework is a dispatch system. While Zend_Controller has the Front Controller and web model hammered down pretty good, Zend_Tool_Framework is an introspective dispatch system for exposing its capabilities via command line (cli), XML-RPC, SOAP, or any other [insert your remoting platform of choice here].
  • Zend_Tool_Project is a profile driven system for managing project related resources and their relationships to one another, the ability to create them, remove them and alter them within the lifecycle of a projects development.
  • Zend_Tool_CodeGenerator is an abstracted system for generating code, including but not limited to PHP. Plans are in the works for generating Apache configuration files, ini and xml configuration files… all wrapped up in an API that is natural and similar to the API’s you’ve already become accustom to inside ZF.

So, that said.. What does this have to do with the PEAR channel? ZF is moving from a library of “runtime components” into more of a holistic framework with capabilities of code-generation, scaffolding, and project management, which complicates the process of installation. PEAR installer is really good at installing code into an already running PHP stack, be it site wide or local. So, by delivering ZF through the PEAR channel, the complexity of installation is shifted off of the consumers and onto the delivery channel.

So what does “installing” mean? It means some elements of the package need to go into some pretty specific areas on your system for them to work correctly. For ZF, it means you will need to put zf.sh or zf.bat in your executable path, zf.php in the php_bin directory, and put the Zend Framework inside your include_path. If you’ve used tools like PHPUnit, PHPDoc, or some other framework, this type of “installation” should make sense to you. If not, go poke around you system after installation to better understand.

Details

So, onto the technical details. If you want to see what it can do, first discover and install:

(discover the zf channel)
/my/path# pear channel-discover pear.zfcampus.org

(install zf-devel)
/my/path# pear install zfcampus/zf-devel

(or for something stable)
/my/path# pear install zfcampus/zf

More information will be posted on http://pear.zfcampus.org as it becomes available (this includes other packages in the channel, and other releases like beta and alpha).

To see Zend_Tool in action:

/my/path# mkdir tmp; cd tmp;
/my/path/tmp# zf create project

Now, go explore the project that was created. In addition to that, you can also run “zf show profile” and it will generate a tree of your project. There will be more updates, and more providers available in the coming weeks to show off what we’ve been developing for Zend_Tool. Also keep Zend_Application in mind because as it formalizes, it will be the target of what we will be generating from Zend_Tool and the zf command line interface.

Details, Details, DETAILS!

Like mentioned previously, the pear channel is beta. What could be beta about it you ask? Well for one, the package and release plan that comes along with it. As of this writing, here is the plan:

  • ZF Package
    • Stable (no version modifier)
      • source: tag
      • schedule: on tag
    • RC – Release Candidate
      • source: tag
      • schedule: on tag
    • Beta (beta)
      • source: branch of current release branch
      • schedule: weekly
      • version: current + 1 mini
    • Alpha (alpha)
      • source: trunk
      • schedule: weekly
      • version: current + 1 minor
    • Development (devel)
      • source: trunk patched with selected incubator components
        • maintained in a file in incubator (locally for now)
      • schedule: weekly (or on demand)
      • version: current + 1 minor
  • ZF_Minimal Package
    • (scheme same as above)
    • Source modified
      • no tests
  • ZF_Extras Package
    • planning
  • ZF_Laboratory Package
    • planning
  • ZF_Doc_Lang Package (maybe)
    • planning

This might get tweaked over time, but the idea is pretty solid. Stable comes from tags as well as release candidate (and patch releases if they exist, not mentioned here). Betas are considered the next mini release, and alphas the next minor release. Development is super developmental, as you can see as its cut from trunk with selected incubator components.

More details will be forthcoming as I’m sure there will be questions you might have that are in search of answers. Till then…

Happy ZF-ing!

Author: Ralph Schindler


  • Share/Bookmark

by News Robot on August 28, 2010 in News, No Comments »
tags: ,