Please note that this story is over 18 months old. It may be outdated.

After reading the articles in the December 2007 php Architect magazine, I thought that I should be able to get access to php from at least ECL.

At the IBM U2 University, they covered something similar for python. It’s not available yet, but why wait?

As I use CentOS 4 in VMWare, the version of php is 4.3.9. I removed this via rpm -e and downloaded the latest source of php 5 (5.2.5).

After downloading, uncompressing and extracting the tar, I compiled the code:

./configure -disable-cgi
make
make install
make install-cli
make install-pear

The -disable-cgi option when configuring and the install-cli when making, make sure that the CLI – Command Line Interface is installed.

I tested the installation by running php from the shell prompt:

[root@UniVerse ~]# php -v
PHP 5.2.5 (cli) (built: Jan  9 2008 18:51:26)
Copyright (c) 1997-2007 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies
[root@UniVerse ~]#

All looking good!

Now, to run an operating system command from within ECL, it is as simple as creating a new verb in the VOC. I based it on the SH verb:

PHP
0001 V - PHP CLI interface
0002 /usr/local/bin/php
0003 U
0004 TICGR

The format of a verb, in particular the Dispatch Type and Processor Mode, is covered within the UniVerse ‘Administrating UniVerse’ manual, chapter 18 – Adding Capabilities to UniVerse.

Now the test at ECL:

>PHP -v
PHP 5.2.5 (cli) (built: Jan  9 2008 18:51:26)
Copyright (c) 1997-2007 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies
>

OK, now what? Well, there is a large amount of free code, blogs and articles for php on the internet; from simple email address validation (a rather complex check actually) to complete web page/html breakdown and extraction.

So a simple use of php is generating a HASH or message digest for a line of text. This is normally used for electronic signature generation within documents and emails:

check the php hash function page: http://us2.php.net/manual/en/ref.hash.php

At a shell prompt:

[root@UniVerse ~]# php -r 'echo hash("md5", "Hello World"),"n";'
b10a8db164e0754105b7a99be72e3fe5
[root@UniVerse ~]#

where the -r option runs the code on the command line.

And at ECL:

>PHP -r 'echo hash("md5", "Hello World"),"n";'
b10a8db164e0754105b7a99be72e3fe5
>

The “n” adds a trailing line feed to the output string.

This can now be used with a UniBasic routine via the EXECUTE or PEFORM statements. One interesting issue that I have found between these two statements is the return of the exit code from the php script. The article covers the generation of an exit code rather well, and why to use one. What I found was that PERFORM will return the exit code and make it available within @SYSTEM.RETURN.CODE. I could not make this work using the EXECUTE statement.

Next step? Well using the PECL extensions within php, install the html parser and start screen scrapping!

But, there are some issues here. A PERFORM from UniBasic has to be used, and that can be slow. Also, the transferring of variables/data is bothersome. A dll linked into UniVerse would be better…