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…
Enjoyed your article on PHP in Universe. A very creative way to get to PHP from UV.
At a previous job, a co-worker implemented InterCall in a PHP library. It enabled us to use all of the functionality of BASIC from PHP calls on our web server. It was a great way to add dynamic data to our web pages.
Thanks for your comments Ken.
I know that UniVerse and Unidata have significant and good support for external applications to use the database and it’s environment. I have also done work previously external to UniVerse and extracted or inserted data; reliably with the U2 tools available.
As I really hate reinventing the wheel and I would like to sit inside UniVerse and use all the existing code available on the ‘interweb’ thing. But, mainly this code is written in other programming languages. The amount of code snippets written in PHP, Java, Python and Javascript is huge. Wouldn’t it be nice to use it all within UniVerse without the overhead of SOA or other complicated mechanisms?
PHP by default wants to look for the php.ini file within the library directory rather than the /etc directory.
To conform to standards, configure with:
./configure -disable-cgi –with-config-file-path=/etc/php
and create a ‘php’ directory within the /etc directory.
As a matter of interest, the RPM install creates a /etc/php5/ directory!