Tag Archives: PHP

ZendCon2017: You’ve heard all about PHP 7, now let’s get busy and start using it!

I’m looking forward to getting out to ZendCon 2017 this year for many reasons. Networking with folks I just don’t see that often is definitely a high point, but getting busy with PHP 7 is certainly the hot topic that I’m most looking forward to exploring. The adoption statistics for PHP 7, while better than previous major transitions, still have a way to go. Why? Because learning about PHP 7 is only half the loaf. As the Nike ad likes to say, you’ve got to “just do it” – and there will be plenty of that at ZendCon; people talking, sharing and hacking all over the place.

I will be hosting two of my favorite sessions “Who’s doing what with PHP on IBM i” on Wednesday and “IBM i panel discussion” on Thursday.  Both sessions represent great places where you can learn more about how to leverage this amazing technology right on IBM i. In the “Who’s Doing What” presentation, we’ll be highlighting great IBM i shops like Newlyweds Foods, T&A and Hydrite Chemical. You can see how these companies leverage diverse and powerful applications that impact their bottom line. I have been lucky enough to recruit the top minds for PHP on IBM i for the panel discussion, including the product manager for Zend Server, Mickey Hoter, who just might make an announcement or two. You never know what you’ll learn at the panel! Be sure to come with your best questions for the panelists to mull over and debate.

I already have my invitation to the IBM i reception. Make sure you check IBM i on your registration so that you can get your own invitation.  It is the premier social event for the IBM i faithful at ZendCon, so don’t miss it!

-Mike Pavlak

The new PHP stack on IBM i Improves Performance and Configuration

The introduction of Zend Core to the IBM i opened a new world of possibilities for IBM i developers trying to create web applications that would make use of their existing DB2 files while hosting them on the same system. Zend Core was the first step on porting a reliable PHP stack to the IBM i world and while it was indeed a great first step, there was also room for improvement.

The Zend Core distribution made use of an Apache instance that ran in the PASE environment, leaving the IBM HTTP Server Powered by Apache working as a reverse proxy mainly passing the requests to the instance in the PASE environment. As more advanced PHP applications were developed, developers and administrators began to struggle with more complex Apache directives and configuration that were needed because of the reverse proxy. Zend and IBM worked on a solution to eliminate this problem: The new Zend Server for IBM i. In addition to eliminating the Apache server in PASE, new and improved caching algorithms were introduced that have the capability to deliver great performance improvements depending on the nature of the applications.

Mike Pavlak goes into further detail explaining Zend Server’s packaging, new architecture, installation and server versions (Community Edition and Commercial Edition) on the “What’s New with PHP on IBM i?” article hosted at SystemiNetwork.

For those of you that are currently using Zend Core, we recommend the upgrade to Zend Server CE. You can read our KB article “Using WebSmart PHP with Zend Server CE” to get information on how to download and setup Zend Server CE.

New WebSmart Updates, Examples & KB Articles. Last Call to Sign up for WS ILE Online Training.

We have recently created new WebSmart example programs and published many KB articles that may be useful to you. Also, registration closes on Saturday for the WebSmart ILE online training, and there are some new updates you should be aware of.

WebSmart 8.8 IDE Update
WebSmart IDE version 5983-8198 is available for download. This updated version of the IDE resolves two issues: getparm would not retrieve values into a structure, and some View Data problems with user input values in Clover. We also added additional JavaScript keywords to the context-sensitive F1 help.

WebSmart 8.8 Feature Spotlight: jQuery
Developers wanting to use more powerful web development features will be particularly excited to see that in WebSmart 8.8 we switched our templates to use the jQuery JavaScript library. If you aren’t yet familiar with jQuery it’s well worth spending a few hours reading up on it online and reviewing some of our own online examples. We use it extensively ourselves, both in our software tools and our professional services work.

WebSmart 8.8 is the latest release of the software. Check our web site for an overview of the new features, or view the recorded webinar.

WebSmart 8.2 Updates
Just before releasing WebSmart 8.8 we had created a few updates for WebSmart 8.2. You can find more information about these updates at the WebSmart server and client side updates history pages.

These fixes are included in version 8.8, but if you aren’t ready to upgrade and would rather just apply them as updates to your current installation of version 8.2, email us to request download instructions.

Last call for WebSmart ILE Online Training
Registration for next week’s first WebSmart ILE online training course ends this Saturday. You can attend these 2 hour courses from the convenience of your office at the low cost of $149 per course. You can register for individual courses or all of the following topics: WebSmart templates, intro to PML, passing parameters, getting user input and validating the data, stateless programming and security. Enroll or learn more >>.

New Code Samples
We have published several code samples you can use as you create WebSmart applications:

  • Example 214 illustrates how to use jQuery to quickly display list record details in a pop-up window without loading a separate page.
  • In Example 213 we helped a client resolve a validation problem where users were submitting data that included specific characters they could not have in their files.
  • Example 206 describes the steps to create a web service using PHP and SOAP.

Let us know if you have any questions or comments on these, or need help implementing them!

New KB Articles
Our Tech Team has also been busy writing new KB articles. Here is a sampler:

  • A solution to a problem with PHP programs timing out before fully loading very large pages.
  • Information on how to work with PDF and Excel files in your PHP programs.
  • How to check which WebSmart service programs are currently used by your applications (a great new feature in WS 8.8!)
  • A way to add compiler directives to your programs via the PML.
  • Advice on where to look if you have issues with user-written functions after an upgrade.
  • Suggestions on how to use SQL scalar functions for enhanced functionality in the PML.
  • Information on the option to log program execution time.
  • An approach to limiting the number of records returned by a Clover report.
  • A technique for adding post-processing actions (deleting a work file) to Clover programs.

These are just a few of the new articles. There are also many others that include troubleshooting and error information for obscure compile and runtime errors.

jQuery UI Autocomplete, JSON and PHP

In case you are not familiar with the term ‘autocomplete,’ it refers to the kind of functionality you get with Google mail when typing a ‘to’ email address, or in Google Suggest.  As you type characters in the search box, it ‘autocompletes’ by providing you a list of matches. The list gets refined the more you type.  We also have  a WebSmart example you can try out live.  Autocomplete widgets can help make your applications more user-friendly, because they make it much easier for users to find items in large sets of data.

We’ve used Autocomplete plugins in a number of our web applications (both for customers and internal use) for some time now. I just stumbled upon the relatively new jQuery UI Autocomplete plugin. There is some good example code at the jQueryUI site.  Another good tutorial on how to use it is this one.

This post explains how to code it for a typical usage. Note that although I am using PHP here, you can accomplish exactly the same thing with PML and DB2 SQL in WebSmart ILE.

Here’s a sample image from a work in progress (new customer log system using jQuery, AJAX, PHP and MySQL). I’ve blurred the customers, as this is real data from our files.



Let’s look at the code required to implement this. First, the client-code (jQuery and JavaScript).

Client Code

			minLength: 3,
	 	    delay : 400,
			source: function(request, response) { 

				   url: 	 "index.php",
				   data:  {
				   			mode : "ajax",
				   			component : "consearch",
				   			searcharg : "company",
				   			task : "display",
				   			limit : 15,
				   			term : request.term
				   dataType: "json",

				   success: function(data) 	{



		   select:  function(e, ui) {
				var keyvalue = ui.item.value;
				alert("Customer number is " + keyvalue); 


The important pieces here are the source property and the select event. The source property really defines 2 key aspects of the autocomplete widget: the source (input) of the data to populate, and how to put it in the autocomplete box (formatting, etc).

First, it defines the source of the data. This can be a local Javascript array – useful for small, relatively static data sets such as State abbreviations. It can also be a string with a value of a URL. The URL will point to a script (see below for example code) that gets invoked via AJAX and returns an array of items. While this may seem the obvious choice for most cases, it’s really not that useful because you have no control over how you format your response data. The third possibility, as shown in the example code above, is an anonymous function. This is the most useful coding pattern. The function accepts two parameters- request and response. Request is an object that has a property called term, whose value is whatever the user types in to search for. So, if the user types ‘AME’, then request.term == ‘AME’. Response is a callback function name that implicitly accepts one parameter, the data to display in the autocomplete results box. This is poorly explained and documented on the jQuery UI site. I only really understood this by reading Dan Wellman’s article. Look at the client code above and you’ll see this line:


That’s a call to the manufactured callback function. You’ll notice, also, that in order to actually do anything, you have to explicitly code the ajax call in the callback function for the source property. This is quite a different coding pattern than what we used with the ‘old’ jQuery autocomplete plugin, but the whole design of this code is so much more elegant and flexible.

The other key piece in the client-side code is the select event. This event is triggered when the user clicks on one of the values in the list. In my example code this just causes an alert box to popup that shows the value of the customer number. The select callback function accepts 2 parameters- the event object (not sure why you’d want that) and the ‘selected item’ object (which I’ve called, by convention, ‘ui’). Note that ui has an object called ‘item’ as one of its properties, which in turn has ‘value’ as a property. Hence: ui.item.value refers to the value of the selected line. You can have other, custom properties besides the 2 standard ones (‘value’ and ‘label’), as shown in this example.

I could not find formal documentation describing ui.item, only example code.

In the real world, the next step would be to do either a redirect or an AJAX call to a script/program that lets me work with my selected customer. I’d likely include the customer key in the url, for example:

  var surl = "index.php?task=edit&custno=" + ui.item.value;

Next, let’s look at the server code.

Server Code

	$searcharg  = getparm('searcharg');
	$limit = getparm('limit');
	if (!$limit) $limit=10;
	$sercontact = '';
	$sercompny = '';
	$term = getparm('term'); 

	 	$sercompny = strtoupper($term);
		$query = "SELECT  CLCLNU, CLCLNA FROM CS_CLTF WHERE clclna like '%" . trim($sercompny) . "%' order by CLCLNA";  

	$query = $query." LIMIT  $limit";  // Limit results based on the limit parameter from the ajax call. 

	$rows = $db->get_results($query);  // Populate result set
		// While we retrieve a row from the result set:
	if ($rows)
		foreach($rows as $row)
			$companies[$count] = array("value" => $row->CLCLNU, "label" =>  $row->CLCLNA);
		echo  json_encode($companies);

(FYI I’m using the EZSql library here to do my SQL coding. EZSql is a PHP library that makes coding SQL statements simpler, and supports multiple databases. A comparable library is PDO, part of Zend Frameworks. EZSql is Free and Open Source).

Note the use of json_encode. What this does is produce a JSON-formatted  array of  objects. Each object has a property of “value” (the customer number – key to the customer table) and “label” (customer name- what appears in the autocomplete). Even though I assign these values to an associative array, json_encode treats it like an object when it translates it (which makes sense when you think about it, and is documented on php.net as intended behavior).

To be a little more clear, the returned data from the PHP script to the AJAX callback will look something like this:

[{"value":"3215","label":"COMMUNICATION INC."},
{"value":"8243","label":"ACME MANUFACTURING COMPANY"},
{"value":"5713","label":"ABCDEFS COMPANIES, INC."},
{"value":"4869","label":"ABERYSTWYTH AVENUE COMPANY"},
{"value":"223","label":"ALLKINDS COMPRESSOR"},
{"value":"3705","label":"MIGHTY INSURANCE COMP"}]

It seems to me this Autocomplete plugin is way better than the jQuery autocomplete plugin I’ve used before, particularly since it uses the jQueryUI CSS framework to style the autocomplete dropdown box. It’s more flexible, you can define the code in one object call instead of two, and it’s more likely to be supported and maintained by the jQueryUI team.

Time, Times and Half a Time

A while back I came across the following in an email:

echo "Hours difference = ".floor(($d2-$d1)/3600) . "<br>";
echo "Minutes difference = ".floor(($d2-$d1)/60) . "<br>";
echo "Seconds difference = " .($d2-$d1). "<br>";
echo "Month difference = ".floor(($d2-$d1)/2628000) . "<br>";
echo "Days difference = ".floor(($d2-$d1)/86400) . "<br>";
echo "Year difference = ".floor(($d2-$d1)/31536000) . "<br>";

Can you spot the bug(s)?

Epoch time is seductive in its apparent simplicity, but can come back to bite you.  The gotcha above is the assumption made that a day consists of 86400 seconds.  In fact, twice a year, a day can have more or fewer seconds: when we switch to DST and when we switch back.

So what to do?  There are various alternatives depending on what you used the magic number 86400 (or its multiples) for.  If you’re trying to calculate a date ‘x’ days in the future, you can do something like this:

$Timestamp = strtotime("+90 day", $Timestamp);

If you have two dates already and want to know the number of days between them, you can convert the dates to times and then divide by 86400 and round the result.   You can read all about it here:


In the comments at the bottom of the date function documentation you can find other helpful variations on the above theme (beware, some require specific versions of PHP).

You may need to clarify what level of precision is required in your calculations.  Are you looking for how many days (24 hour periods) are spanned by two epoch times or how many calendar dates?  Is an approximation good enough?  Are you ok with the result being rounded up?

Moral of the story: Using magic numbers for the number of seconds in a day (or any greater unit of time) can come back to bite you.

WebSmart News: Ending IE6 support, V6R1 upgrades and training reminder

There are a couple of technical issues I want to share with you, and I’ll also take the opportunity to remind you about the web training classes coming up this month.

IE6 Support Will End at WebSmart 8.8
At WebSmart 8.8, the next major release of the tool, we will stop intending to support Internet Explorer 6 for our templates, code snippets and other generated HTML, CSS and JavaScript. This also affects the versions of Clover and SmartCharts that ship with that release.

Our internal sentiment on this matter is similar to Google’s.

Upgrading to V6R1
Over the years we have noticed that there can be a spike in OS/400 upgrades about a year after IBM first makes a version available, and we’ve recently had a surge in V6R1 upgrade questions.

If you are currently planning your own upgrade please review the information in KB article 7292. You should particularly be aware that the default port used by Exodus, 2015, is no longer available to us and needs to be changed. This last issue is the one that most often catches people.

$99 WebSmart Online Training Promo Ends April 2
The $99 introductory promo for the new 2 hour online WebSmart ILE and PHP training courses ends tomorrow, April 2nd. The courses will still be available after that, but at a higher rate.

These courses are a convenient and affordable option for you or any in your organization who is new to WebSmart to learn about WebSmart templates, passing parameters, getting user input and validating the data, stateless programming and security. Enroll or learn more >>.

Complimentary Beginner Webinars on HTML, CSS and PHP
And finally, if you are new to HTML, CSS or PHP don’t forget to sign up for our three complimentary educational webinars:

These are intended for anyone whose job is starting to require they have a functional knowledge of these technologies. These skills are relevant to WebSmart, Clover, Nexus and Presto.