Operating System - OpenVMS
1745833 Members
4102 Online
108723 Solutions
New Discussion юеВ

A Little Help With PHP VMS File Reads

 
Robert Atkinson
Respected Contributor

A Little Help With PHP VMS File Reads

I'm trying to use PHP to read an index, fixed-length file.

If I use file() I just get everything in index 0 of the array.

If I use file_get_contents, there's nothing to show where one record ends and another begins. I'd have to hard-code the record length to read the file properly.

fread() is the closest I get to processing the records, as it carries a LF through into the resultant data.

When I try these out on variable length files, I get NULL, ETX (End Of Text), NULL between the records.

Does anyone have any sample scripts, or can tell me the proper method of reading both fixed-length and variable length files by record?

Thanks, Rob.
9 REPLIES 9
Steven Schweda
Honored Contributor

Re: A Little Help With PHP VMS File Reads

What I don't know about PHP would fill its
manual, but I'd be pretty amazed if it had
the ability to deal well with any file format
other than sequential (with Stream_LF records
being the safest).

I'd guess that you're just seeing the byte
stream, which is not what you'd want on the
more exotic file formats.

Perhaps you could use the "system" function
to run a real (RMS-aware) program which could
do the I/O and pass the data back.
Wim Van den Wyngaert
Honored Contributor

Re: A Little Help With PHP VMS File Reads

May be you can use ODBC for RMS because ODBC is supported by PHP.

Wim (1 year and 7 days without PHP)
Wim
Wim Van den Wyngaert
Honored Contributor

Re: A Little Help With PHP VMS File Reads

May be you can use ODBC for RMS because ODBC is supported by PHP.

But I would go for the solution of Steven. You can even use DCL.

Wim (1 year and 7 days without PHP)
Wim
Robert Atkinson
Respected Contributor

Re: A Little Help With PHP VMS File Reads

We're talking about reading thousands of records, so DCL or running a shell command is not an option - that's why I'm trying to do this in PHP!

If you can tell me where I can get a free VMS ODBC driver for RMS , I'd be happy to try that.

Rob.
Hein van den Heuvel
Honored Contributor

Re: A Little Help With PHP VMS File Reads


>> I'm trying to use PHP to read an index, fixed-length file.

I think you mean an "RMS Indexed file with fixed length records", not an index, not a fixed length file like you wrote. Correct?
To be sure can you post a reply with DIR/FULL output included or attached?

RMS Indexed file _can_ contain just text, but in a pinch contain 'binary' data such that inserting arbetrary record seperators would be silly. No sequence would be safe, some just more likely to be safe. It would need a record size mechanisme or something. So slurping the file with file_get_contents should never work (imho) for variable length records. For fixed length records, as long as you can figure out, or just know, the record length the program knows how to interpret the buffer as multiple record-sizes chunks.

The 'file' interface however promisses to return a record per aray element. I'm surprised to learn it does not.

My guess is that it was (accidently) told that it should not make record boundaries visible. In RMS terms that would be record-attributes = NONE. Try changing that to indicate record boundaries are meaningfull by using: $ set file/attr=rat=cr ...
(to set back: $ set file/attr=rat=none ...)

If I am right, and we are talking about rms indexed files, then going ODBC would be insane (just mho). Why build up a whole stack of relation access methods to get the plain data whne that data is plainly accessible on the box?! Call out to a simple C program calling RMS SYS$GET, SPAWN a task to convert the data to a stream_lf file, or use DCL to access indexed file records.

>> We're talking about reading thousands of records, so DCL or running a shell command is not an option - that's why I'm trying to do this in PHP!

Are you sure? Did you try? The RMS indexed file access code is thousands of instructions per record. A few hunderd more from DCL vs a few dozen more for a C program might not make that much difference. Adding an odcb layer (with client server architecture?) will add multipel thousands of instruction of overhead per record... probably much more than DCL. For simple read-read-read, DCL will do fine, and it can doe keyed reads as well. The main overhead it does is to call translate-logical on the stream name every time again.

>> If you can tell me where I can get a free VMS ODBC driver for RMS , I'd be happy to try that.

Try DCL first. It's free.

Regards,
Hein van den Heuvel
HvdH Performance Consulting.
Steven Schweda
Honored Contributor

Re: A Little Help With PHP VMS File Reads

It's often hard to supply the optimal
solution when the whole problem is not known,
but consider that it's possible to write a
C (or other language) program which can read
an RMS indexed file, do some work, and spew
HTML. Such a program could do a good deal of
(potentially efficient) file I/O with only
one process creation.

Many things are possible.
Jean-Fran├зois Pi├йronne
Trusted Contributor

Re: A Little Help With PHP VMS File Reads

If you want to use a scripting language, you can try Python which has a interface for RMS indexed files.
There are 2 examples on http://vmspython.dyndns.org/

JF
GuentherF
Trusted Contributor

Re: A Little Help With PHP VMS File Reads

"running a shell command..." UNIX ALERT!

A DCL command does not create another process. Some DCL commands like the OPEN/READ/WRITE/CLOSE do not even activate a program. Doing this type of file access in DCL is not that bad performancewise.

/Guenther
Robert Atkinson
Respected Contributor

Re: A Little Help With PHP VMS File Reads

I never really found a solution to the problem, so did what every good programmer should do - ignored it till it went away :)

Just joking of course.

There are mutterings that future versions of PHP may have RMS support in them, but I may not be around long enough to see it.

Rob.