Posted: November 12th, 2009 | Author: enrico | Filed under: Books | Tags: framework, Books, mvc, PHP, zend, Zend Framework, Zend_Application | 2 Comments »
I’m reading the new book of Keith Pope, “Zend Framework 1.8, web application development” of PackT Publishing and my first impression is very good!
This book introduces the Zend Framework (ZF) using a direct approach to build a real web application in depth, in particular an e-commerce web site (you can download the source code of this application from the PackT web site).
In my opinion this is a very good approach because the main difficulties when you start a new php application using the ZF and in general the MVC paradigm are: how to structure the application, where to write the code, how to build the models, etc.
I guess this is one of the first book about the new version 1.8 of ZF. As you know starting from the version 1.8 the team of ZF has introduced the Zend_Application class to easly manage the configuration and the bootstrap phase of the application using a .ini file. The usage of the Zend_Application is showed in the Chapter 3 of the book.
Especially useful is the part of Model design in the Chapter 4, where the author shows step by step how to build a model and why. For instance the author presents the Model of a Product showing the balance between the Controller and the Model, and the general rules to follow: code reuse, controller readability, maintainability, etc.
I’m glad to the author to have inserted the Chapter 12 about testing the application using PHPUnit. This is a very important part of every software developing life cycle and sometimes in the real life someone forgot to test! Me too, i’m honest
In conclusion I strongly suggest this book if you are interested in developing php web applications using the Zend Framework, whether you are a newbie or and experienced ZF developer.
For more information about this book you can go to the publisher web site here.
Posted: April 25th, 2009 | Author: enrico | Filed under: Zend | Tags: job, PHP, platform, queue, zend | 6 Comments »
One of the features of the Zend Platform is the Job Queue, a server application that is able to schedule and manage the execution of php scripts (jobs).
The Job Queue can be used to create asyncronous execution of php script and provide, for instance, the scalability of a server application (for more info read the White Paper “Scalability and Responsiveness with Zend Platform’s Job Queue” by Dotan Perry and Shie Erlich).
You can manage the Job Queue feature of the Zend Platform with a web interface (see the figure below) or directly in PHP with an API system.

Using the web interface you can schedule the execution of a job (a php script) that is located into the JobQueue directory of the Zend Platform (the default is /usr/local/Zend/Platform/JobQueue in a Linux environment). You can also suspend and resume jobs from the queue, view the statistic of the job queue, view the history of each job execution and setting the parameter of the queue (maximal queue depth, maximal re-queue times, queue alias, scripts folder, etc).
As I said you can use the job queue also from PHP with the use of a API system. Basically the Job Queue Zend API contains two main classes to manage the connection to a queue server and to schedule the execution of jobs. This classes are ZendAPI_Queue and ZendAPI_Job. Is very easy to use this API and you can schedule the execution of your php script in a few lines of code. Let me show this introducing some examples.
In order to connect to a queue server you have to specify the host:port address and the password of the queue server (the default port of the queue server is 10003). Here there is an example:
1
2
3
4
| $queue= new ZendAPI_Queue('192.168.1.10:10003');
if ((empty($queue)) || (!$queue->login('password'))) {
throw new Exception('Error on queue connection');
} |
When you have established a connection you can manage the scheduling of a job. For instance here we scheduled the execution of a job named send_email.php for the next 4 hours.
1
2
3
| $job = new ZendApi_Job("send_email.php");
$job->setScheduledTime(time() + 4*3600);
$id = $queue->addJob($job); |
If you want to search for a job into a queue server you can use the getJobsInQueue method of the ZendAPI_Queue class.
For instance you can remove the failed jobs from a queue server with the following code:
1
2
3
4
5
6
7
8
9
10
| $queue= new ZendAPI_Queue('192.168.1.10:10003');
if ((empty($queue)) || (!$queue->login('password'))) {
throw new Exception('Error on queue connection');
}
$jobs_status = array(status=>JOB_QUEUE_STATUS_LOGICALLY_FAILED);
$all_failed_jobs = $queue->getJobsInQueue($jobs_status);
foreach ($all_failed_jobs as $failed_job) {
echo "removing job $failed_job from queue...";
$queue->removeJob($failed_job);
} |
In this post i introduced only the main functions of the Job Queue Zend API, for the complete list you can read the User Guide of Zend Platform 3.6 at pag. 295-305.
In my opinion using the Job Queue feature of the Zend Platform you can explore a new way to think about web solutions with asyncronous execution of PHP code.