So I decided to make this web application that a user could create a legal form in Microsoft Word (docx) format, and since my web site is in PHP, and I wanted to learn PHP better. Just a few issues:

1) PHP can’t make a Word – .docx document easily. Sure, you can do your bits and bytes and try to decode the entire format. Docx is just an archive, and you can zip up the components, but then you can’t get your compression ratio right, and Word tells you the document is malformed when your browser calls it and blah-blah fricken blah.

OK, so I figure, Java has libraries to do this, and do it easily. So I’ll just make a Java program that will take the form data from the PHP generated form and make the docx. No problem at all, did this in a few hours with no knowledge of the java library that I used (docx4j).

OK, so I jar up the program, make a properties file for paths and so forth, and deploy said jar to the Apache server on a windows system where I’m developing. Now, all I gotta do, is call the Java program from the php.

Whoops.

Calling a java program from php over the host operating system is about as easy as calling the international space station from a tin can with a string on it. To make it worse, I have to deploy on a Linux system making whatever Windows solution I come up with totally worthless. Now I find out about JavaBridge, which my zend php server tells me that it doesn’t like, or home made solutions by changing the apache configuration settings which blows up apache and blah blah fricken blah.

OK, then it came to me. Talking to java over the operating system, isn’t the only way to talk to java. You can talk to java through the file system. How? Just add a java listener to your java program, leave a marker on the file system from php…a text file with the docx’s id number which I had already set up. Have the java listener make the docx, have the php sleep until it sees it. Bada bing bada bang…we have our solution. I wrote the listener in under an hour from scatch. Clean up by deleting the files with a sweep utility after generation. Works faster that any other way too.

Leave a Reply

Your email address will not be published. Required fields are marked *