printing through lpr from php
Hello all :-)
I need to generate printouts of data (on a laser printer) from a PHP app running on Apache/Linux. Unfortunately I'm no Linux expert so I've run into problems that I have no idea how to solve an have been unable to find solutions thus far.
This is what I'm doing so far:
1. Generate the Postscript code for the printouts.
2. Open a process to the lpr using proc_open() with the following command:
lpr -P 128.3.1.5:dp65 -J Cartas --stdin --nodialog
I previously installed the rlpr package on the server and have been able to print static postscript files succesfully on the host. "Cartas" is the intended name for the print job.
I open the process with a pipe for the process input, and files for the output and error stream.
3. Pipe the generated postscript code to the opened process.
4. Close everything.
On step 4 I get an exit value of 1 (not OK).
When I check the file set for error output it has the following line: cannot connect to X server.
I get no type of PHP error and the generation of the postscript code is ok (I checked it independently) and I'm pretty sure of handling the whole process openening with pipes and files correctly. In other words, I'd consider the PHP code to be ok.
I'm guessing the lpr command I have installed is trying to open sort of window and can't. When printing from command line with the -- nodialog option I will still get a confirmation window saying the jobs have been sent to printer. It might be the command is trying to open this final confirmation window.
I could try to install CUPS but I'd rather leave that as a very final option, since that would mean (AFAIK) installing stuff on the printer host; and I'd rather not.
My questions are:
Does my guess seem right (X-Windows problems)?
Are there any options for the lpr command I might be missing? (doesn't seem so according to the command's --help)
Are there any shell-level "modifiers" or operators that would shut off X-Windows operations in a process?
Is there any other scheme for printing that I could try?
I really appreciate any answer, suggestion or comment.
|