Informing the IBM Community

Tips for a happy Zend Server on IBM i


Abstract technology background with hexagonal shapes

We looked in my last article at how to get started with PHP on IBM i. Server side, this involved installing Zend Server – the PHP engine that makes things happen. In this article, I’m going to share some tips with you that relate to configuring this fine software to avoid problems and get the best out of it.

Configure your character sets

Of all the challenges we have had to overcome with PHP on the IBM i in the past, the biggest and ugliest have been related to CCSIDs. I cannot stress this strongly enough, people; you must get your CCSID set up right from the start.

Before we even look at Zend Server, some database admin. Any file you plan to access from PHP should have a proper CCSID. A proper CCSID is one that isn’t 65535. I don’t care what it is, just not 65535. Personally, I’d extend this rule to cover any file you plan to access from anywhere, but it’s not my job to tell you how to run your life or your database.

The transparent nature of CCSID 65535 means that it is impossible to convert from this to other character sets with any consistency or predictability. Not a great place to be if you want your data to make sense on the web.

If you are planning to capture data in your PHP programs, it might also be worth considering CCSID 1208 for the files that you will save it in. This is the CCSID for UTF-8 and means you’ll be ready to store any tricky international characters that users might throw at you. The drawback with this CCSID is, however, that you will only be able to access your data using SQL, not record-level access within your legacy programs.

And now to Zend Server itself. We are going to change some configuration files in the IFS, an act that itself can suffer from character set issues if done using a 5250 session.

I use an FTP client like FileZilla to access any files that need to be changed so that they are edited locally on my PC. I’d recommend you do the same. And always take a backup copy before you change anything.

The first file to edit is httpd.conf in folder /www/zendsvr6/conf which is the configuration file for the HTTP server instance generated by Zend Server.

Open it up and change the following lines to look like:

DefaultFsCCSID 00285
DefaultNetCCSID 01208

The values of 285 for the first two settings work for us here in the UK but you could set them to a value more appropriate to your location. The net CCSID of 1208, as mentioned earlier, indicates UTF-8.

Also, look for an AddCharset directive relating to UTF-8. If one doesn’t exist, add one like:

AddCharset UTF-8 .htm .html .xml

Save the file and load it back into the IFS.

Next, we’re going to make a small change to file fastcgi.conf, also in folder /www/zendsvr6/conf.  This file contains configuration for the FastCGI jobs which do a lot of the busy work such as running SQL and calling native programs.

Open the file, and look for the first (very large) directive. This will start with either Server or DynamicServer, depending on whether FastCGI is configured to be static or dynamic – more on this later.

Within the directive, look for SetEnv sections that relate to CCSID and LANG. They will look something like:

SetEnv=”CCSID=819” SetEnv=”LANG=en_US”

Change these values to look like:

SetEnv=”CCSID=1208” SetEnv=”LANG=C”

Save the file and load it back into the IFS.

Now we are going to change file toolkit.ini in folder /usr/local/zendsvr6/share/ToolkitAPI which is the configuration file for the XML Toolkit. This is a separate piece of software that allows us to easily access the native database and functions on the IBM i.

Open the file and look for the line where the encoding property is set and change it from the default of ISO-8859-1 to UTF-8. After your changes, the line in question should look like:

encoding = “UTF-8”

Save the file and load it back into the IFS.

The last job is to change a directive relating to the PHP DB2 support module. Fortunately, we can use the Zend console to change this. It is much less scary than FTPing files around the place.

Log into the Zend console, then navigate to the Configurations tab and, within that, the PHP tab. This page lists all the PHP modules installed and allows you to change the associated configuration. You are looking for a section marked ibm_db2. When you find it, click on it to show its directives.

The key value for us here is the ibm_db2.i5_dbcs_alloc directive – . Quite a mouthful. This should be set to use expanded allocations. Without this, you can end up with truncated strings appearing in your database.

Zend Server 1

After all this, you’ll want to end and restart Zend Server.

This configuration should hopefully mean you avoid any character-set problems when you start accessing your database and native resources such as RPG programs from your PHP scripts.

Use multibyte support

Once you have got the CCSID aspects of Zend Server running sweetly, it is worth considering switching on multibyte character support.

This PHP configuration allows you to use character sets that use more than one byte per character – a must if you want to be able to handle anything other than the most basic ASCII symbols.

Again, we can use the Zend console to change this set up. In the Zend console, navigate to the Configurations tab, and within that the PHP tab. Find the section marked mbstring and click on it to show its directives. I recommend the following settings:

mbstring.http_output                   UTF-8
mbstring.internal_encoding        UTF-8
mbstring.encoding_translation     On
mbstring.http_input                     Pass
mbstring.language                        neutral

Zend Server 2

Having gone to all this trouble, it is worth pointing out that when you start to write your PHP code you should be using the multibyte string handling functions that the language provides. There are single-byte functions provided for backward compatibility but these should be avoided.

For more information on the PHP multibyte functions, see the website section on multibyte support.

Switch on compression

For some bizarre reason, Zend Server on the IBM i comes out of the box with compression switched off.

Compression is a feature of the HTTP server that reduces the size of the data being passed back and forth to the browser. Less data means faster transactions and a more pleasant user experience.

As a beginner, this might not seem important but, trust me, once you start deploying applications to growing user-bases it rapidly becomes an issue. So it is good to get this quick win in place early on.

As this is a feature of the HTTP server, we’re back into the realm of editing configuration files, specifically the httpd.conf in folder /www/zendsvr6/conf that we saw earlier. At the top of this file, you will see a load of lines starting LoadModule. If it doesn’t already exist, add one as follows:


And below the LoadModule lines, add a line as follows:

AddOutputFilterByType DEFLATE application/x-httpd-php
application/json text/css application/x-javascript
application/javascript text/html

This tells the HTTP server to compress any eligible data, assuming that the browser request indicates that compression is allowed, which is most cases.

Go dynamic

I’ll end with a slightly contentious one. It is possible to configure the FastCGI jobs in two ways, as I mentioned earlier. Static configuration – what you get out of the box – prestarts a set number of jobs to handle requests. This number of jobs is configurable but fixed. Dynamic configuration is more flexible. It starts with fewer jobs started, but will happily start more jobs to handle increases in workload.

It is generally recommended that you use dynamic configuration. We use it and have found it to work well. The contentious point is that occasionally it can perform badly and the reason for this is unclear – according to the Young i Professionals website, it is probably due to a rare combination of PTFs.

If you do want to go dynamic, Zend very helpfully supplies a dynamic version of the configuration file fastcgi_dynamic.conf in folder /www/zendsvr6/conf. Simply rename the existing file, then rename the dynamic version to fastcgi.conf and you are in business. Don’t forget to apply the CCSID changes to the dynamic version, though.

If you have any questions about these tips, or have others you’d like to share with me, you can find me on Twitter: @pete_samways

Pete Samways is a development manager at Proximity. He is an expert in the development, modernisation and mobilisation of IBM i applications, particularly in the logistics sector. He is responsible for delivering projects on behalf of Gebrüder Weiss and Agility amongst others. You can follow Pete on Twitter @pete_samways.


How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.


One response to “Tips for a happy Zend Server on IBM i”

  1. Will this store UTF-8 characters as a single byte?