Skip to content

Instantly share code, notes, and snippets.

@coudenysj
Created November 14, 2013 12:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coudenysj/7466362 to your computer and use it in GitHub Desktop.
Save coudenysj/7466362 to your computer and use it in GitHub Desktop.
<?php
/**
* Create a PULL socket to receive print requests from the webserver.
* Create a PUB socket to send print requests to the windows laptop.
*/
$context = new ZMQContext();
$pub = $context->getSocket(ZMQ::SOCKET_PUB);
$pub->bind('tcp://*:5566');
$pull = $context->getSocket(ZMQ::SOCKET_PULL);
$pull->bind('tcp://*:5567');
while (true) {
$printJob = $pull->recv();
$pub->send($printJob);
}
<?php
/**
* Receive a print request and print.
*/
$context = new ZMQContext();
$sub = $context->getSocket(ZMQ::SOCKET_SUB);
$sub->setSockOpt(ZMQ::SOCKOPT_SUBSCRIBE, '');
$sub->connect('tcp://server:5566');
while (true) {
$printJob = $sub->recv();
$html = file_get_contents($printJob);
$file = get_temp_dir() . '/printJob_' . sha1($html) . '.html';
file_put_contents($file, $html);
// http://windowsitpro.com/systems-management/how-can-i-print-usb-printer-command-prompt
exec('print /d:LPT2: ' . $file);
}
<?php
/**
* Send a print request to the print-dispatcher.
*/
$context = new ZMQContext();
$push = $context->getSocket(ZMQ::SOCKET_PUSH);
$push->connect('tcp://server:5567');
$push->send('http://server/sale/receipt/' . $receiptId);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment