Created
November 14, 2013 12:59
-
-
Save coudenysj/7466362 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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