pontusab / Cups-PHP-library

CUPS is the standards-based, open source printing system developed by Apple Inc. for OS X® and other UNIX®-like operating systems. CUPS uses the Internet Printing Protocol (IPP) to support printing to local and network printers. This library Let's you talk to printers thru PHP.
http://www.cups.org/documentation.php/doc-1.7/options.html
10 stars 5 forks source link

Missing printers when printers are active. #1

Open eklingen88 opened 8 years ago

eklingen88 commented 8 years ago

I was using a snippet from your getPrinters function to list the printers on our CUPS server for a user to select which printer they will be printing their documents to. This was working great until I submitted the form and the page refreshed, at which point I was missing the printer that I had just printed to.

Looking to find the cause of this issue, I quickly ran an lpstat -p in my server's terminal window after submitting the form. I received the following output:

printer IT now printing IT-440.  enabled since Fri 13 May 2016 03:53:52 PM UTC
printer PK01 is idle.  enabled since Fri 18 Mar 2016 02:20:51 PM UTC
...
printer PK30 is idle.  enabled since Thu 28 Apr 2016 08:19:19 PM UTC

After seeing this and looking at the regex on lines 14 and 15, it became apparent what was happening here. So for my purposes, I am not using the following in place of those lines:

preg_match( '/printer\s([^\s]+)/', $line, $printer );
preg_match( '/printer\s[^\s]+\s([^\.]+)/', $line, $status_code );

The status codes aren't really status codes per se, but they are giving me a clear idea of what's going on with the printer and, for now, will work with what I'm doing.

eklingen88 commented 8 years ago

I forked off and made my changes here. Hope this helps!

:laughing: