ZopeMag's mascot the ZOPE fish


Article Finder
People
Issue 7 - Revision 7  /   May 19, 2004 


 
  ZopeMag Links:
Latest Issue
About the Fish
Issue 10
Issue 09
Issue 08
Issue 07
Issue 06
Issue 05
Issue 04
Issue 03
Issue 02
Issue 01
 
 
Downloads
     
  Letter from the Editor:
   Issue 7

Interviews:
Each issue we interview important people in the Zope world.

  Rob Page

Articles:
Throughout the quarter we cover topics of interest to Zope developers, designers, and users.

  ZEO

  Using XML-RPC

  Archetypes Part II

  PyCon 2004

  Plone Workflow (Worklists, Variables and Scripts)

Product Review:
Too many Products, too little time? ZopeMag keeps you up-to-date which Zope Products are worthwhile downloading.

 
CMFSin
  PHParser/Gateway


Guides:
This quarter we bring you a new SuperGuide. Our miniGuides and SuperGuides give you the background knowledge you need to mastering Zope.

  SuperGuide - Users Roles and Zope Security.
 
 
Downloads
     
  URLs / Download
Products we talk about in this issues Articles and Reviews

  CMFSin
     


PHParser/PHPGateway
Enabling PHP in Zope
- - - - - - - - - - - -

By Samuel Sotillo |  April2, 2004

print
____
 
 
Product name PHParser/PHPGateway
Description A product that allows the integration of Zope and PHP applications.
Release Date 2003/11/07
Version 1.1.0
Rating
(all ratings are on scale of 1-5 with 5 sushi being the best)
Usability
Software Design
Documentation
Usefulness
Categories Web programming / Integration
Size 11 KBytes
Requirements Zope 2.5.x and up. PHP 4.0 and up compiled with – enable-force-cgi-redirect.
Creator Originally by Maik Jablonski, currently maintained by Hewei (hewei@ied.org.cn)
License ZPL
URL Download
Packaged as Zope Product
 
____

Pros

PHP code can be integrated into Zope applications without significant adjustments. It might be possible as well quickly to incorporate legacy PHP applications and code into new Zope-based applications or upgrades.

Cons

The product's sourcecode must be modified for installation. PHP sourcecode must be altered so that the PHP include/require functions can be dealt with. For include_once/require_once functions a search mechanism must be implemented. I tested it with Plone and it worked but since the documentation warns one to be careful and Plone is a rather complex product, portability cannot be guaranteed.



Summary

PHParser/PHPGateway is a Zope product that allows zopists to use their PHP scripts under Zope and Plone. It consists of two objects: a DTML-based object and a folder-like object. It accesses PHP content through CGI allowing Zope to be used as a sort of virtual server.

Introduction

The present review examines an example of the intersection of two technologies, PHP and ZOPE, which may be considered rivals but which, in many circumstances, are actually complementary. The product we are reviewing is PHParser/PHPGateway. Initially developed by Maik Jablonski, PHParser was extended by Hewei and then merged with PHPGateway. In its current version, PHParser/PHPGateway allows both zopists and PHP programmers to get the best of these two competing Web technologies at a minimum price.



Prerequisites and Installation Tips

PHParser/PHPGateway requires PHP 4.0 or up. Because—according to the documentation—neither the Apache module nor the PHP CLI available with PHP 4.3.x “will work,” PHP must be compiled with the “--enable-force-cgi-redirect” option. For more details about how to compile and set up the interpreter, we recommend that our readers consult the PHParser/PHPGateway documentation available at http://zope.org/Members/hewei/PHParser/.

The PHParser/PHPGateway product is available as a compressed TAR file — see sidebar to find out how to download the package. Readers working in Windows environments may use an archiving tool like Winzip to unpack the file — while those working in Linux environments may use the standard GNU tar utility. The most important tip to remember is to unpack the file into Zope's Products/ folder. For instance, with Linux you may proceed as follows:

[root@dijkstra bins]# cd [zope-home]/lib/python/Products
[root@dijkstra bins]# tar xvzf [download-dir]/PHParser-1.1.0.tar.gz

The tar command will create a new folder PHParser-1.1.0/ and then unpack the archive's contents into it.

Before restarting Zope, we need to modify our source file to be sure that PHParser knows where to find the PHP CGI binaries. An explanation as to how to do this may be found in the documentation mentioned above.

Once everything has been double-checked, we must restart Zope. The product description should appear in the Control_Panel as shown in Figure 1.

Figure 1

Additionally, if everything has gone well, we should have two new items listed in the Add Product list: the PHParser and PHPGateway objects.

OK! Now, we are ready to start using the product.

Usage

The two main components of PHParser/PHPGateway work in different ways. The first component, PHParser, behaves like a DTML document. It should be used when all we need to integrate into our Zope application are independent pieces of PHP code. For instance, let's suppose we have a piece of PHP code that can generate bar charts as JPEG images. Now, let's suppose that all we need is the output — i.e., the images themselves. We can import our PHP code into Zope by clicking onto the Add Product list and selecting the PHParser object. A new View like the one shown in Figure 2 should then appear.

fig. 1
Figure 2

Figure 3 below depicts an example of a piece of PHP code imported into Zope. This piece of code can generate a bar chart satisfying certain parameter values — of course, for economy's sake, we will not explain the details of this code. The important point here is that our legacy code has been translated into the standard look of a DTML object — that it has, so to speak, been translated into a ZODB object. This means that we can use it the same way we use any other DTML document — for example, we can pass values to it, we can call other objects or scripts from it, and so on.

fig. 1
Figure 3

Another possibility, which is particularly interesting for our case, is that we can invoke this DTML document from inside an HTML tag such as an <IMG> tag. Figure 4 shows an example of this. In this case we have an index_html template that uses an <IMG> tag to invoke php_bar_graph as its source.

fig. 1
Figure 4

What happens here is that the DTML object php_bar_graph is first rendered by the DTML engine which then passes the PHP code to PHP CGI. The result returned by PHP CGI is then echoed by Zope — in this case, the result is an image on the screen. Figure 5 shows the Test View of index_html.

Figure 5

The second component, PHPGateway, works in a very different way. First of all, it is a “folder-like object.” It is useful when what we need to integrate into Zope is a whole site or a complete directory structure. PHPGateway does not translate our PHP code into ZODB objects. On the contrary, all that PHPGateway does is define a pointer to the location in the file system where the code is located. On demand, every PHP file within such a directory structure is passed to PHP CGI — without DTML rendering — as needed.

Figure 6 shows the Add PHPGateway View. The only parameter that needs explanation is docroot. It is the path of the directory structure our PHP files are located in. It is important to note that such a directory must contain a recognizable index-type file — that is, that within the docroot folder there must be a file named either index.php or default.php.

Figure 6

Once created, we can test our new PHPGateway folder by using its View option. Figure 7 shows the result of our sample: a bar chart generated with PHP's Panachart library — for more information about this excellent library go to http://www.panacode.com/.

Figure 7

Another interesting advantage of PHPGateway is that Zope can publish its content as a virtual hostname. For instance, Zope published our test site as http://localhost:8080/pruebas/php_test/panachart_test/, using Zope's standard addressing scheme. However, an alternate approach could be to use http://panachart.our-domain.com/ instead — where panachart.our-domain.com is a virtual hostname.

File Includes

One interesting property of PHP is its ability to include other PHP files into a single source. PHP has different ways of doing this -— two very common ways are the include() and the require() functions. Both functions use the file path as their parameters. However, because PHParser translates the original PHP files into ZODB objects, using the file path as a parameter for this function has no sense. Traditionally in PHP, if we want to include one file within another, we use the following syntax:

<?php
	// include file “myfile.php”
	include(“myfile.php”);
	...
?>

A similar approach must be used with either the require_once() or the include_once() functions. Hewei has written an excellent how-to about this and other topics which is available in the PHParser/PHPGateway home site at Zope.

Product Review End.


Samuel Sotillo:

Samuel Sotillo is a free-lance writer from Venezuela. His interests are: Zope, transactional systems, Python, PostgreSQL, MySQL, Web services, and Latin-American literature and history.


shim
shim  ZopeMag is committed to bringing you the best in Zope Documentation. shim
shim


Home   Subscribe   FAQ   Contact   Write for us   Privacy Policy   Weekly News   PyZine   opensourcexperts.com  

Reproduction of material from any of ZopeMag's pages without prior written permission is strictly prohibited. Copyright 2003 - 2005 ZopeMag Zope/Plone hosting by Nidelven IT