简体   繁体   中英

PHP Printing to Remote Printer

I have a remote POS printer it uses the ESC/POS protocol. I have a PHP app running that prints messages:

    $texttoprint = "Samuel is a legend \nHello. \nTest123";
    $texttoprint = stripslashes($texttoprint);

    $fp = fsockopen("10.1.1.100", 9100, $errno, $errstr, 10);
    if (!$fp) {
        debug("$errstr ($errno)<br />\n");
    } else {
        fwrite($fp, "\033\100");
        $out = $texttoprint . "\r\n";
        fwrite($fp, $out);
        fwrite($fp, "\012\012\012\012\012\012\012\012\012\033\151\010\004\001");
        fclose($fp);
    }

It works but only sometimes, if i run the code it works around 1 in 10 times but it is not hitting the error so I don't know why its only printing sometimes.

Using only one fwrite() fixed this issue. Thank you @user113215. If anyone knows why I would love to know.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM