System i SQL Record Locks and PHP

This is just a reply to a forum post I made some time ago. Thought it wise to save it here, lest I forget where it was at =)

Their response is what I was expecting - all db resources in the web world are generally destroyed between each request (the stateless-www). Unfortunately for those of us interacting with software that operates under a different paradigm - this simply wont do.

At my previous employer (I freelance now) we made this work by writing an RPG program and a CL program. When PHP needed to lock a record - we called the CL passing it the file and record that we wanted to lock. The CL would then call the RPG-lock program and it would lock the record for us.

You may have a couple questions on how this really worked, and why we chose to call a CL that called an RPG program… so let me explain a little(and be assured - THIS DID WORK WITHOUT A PROBLEM FOR US).

First off, we had to call a CL from PHP -> which in turn called an RPG program, so that the CL script would end successfully which would allow our PHP script to continue processing (otherwise our PHP script would wait indefinitely for the RPG program — which is keeping a lock for us).

Second, I developed a PHP 5 framework with the System i / i5OS in mind - while doing so I wanted to deeply integrate the PHP SESSIONS - so that they could easily interact with Green Screen Sessions. While doing so - we managed to come up with a system that involved a DataQ for each PHP SESSION. Using the Dataq we could pass messages to interactive Green Screen sessions, other interactive PHP Sessions, and even messages to RPG programs (such as our Record-Lock program). Whenever we called the Record-Lock CL we passed it the PHP SESSION’s dataq. Since the RPG-lock program now knew what PHP Session called it (via its DataQ) - it would sit and wait for an UNLOCK instruction to be placed into the DataQ.

So the PHP Session could go through multiple pages and not worry about the record lock disappearing. And whenever it was ready to update and unlock the record - it would just drop the UNLOCK instruction into its dataQ.

There were a few other things to consider (what happens if the person in the web browser clicks that red X in the top right?), but we were able to solve those as well.

I hope that gives you some idea of how you can solve this issue - because it is doable!

The original post can be found here

Comments are closed.