-1

I am implementing the functionality for print the invoice, for that i have using the Escpos Module, but when i run this there is no response.

if i print the php_sapi_name i got the "apache2handler" instead of "cli", i have the linux system. i don't know how to get "cli" in my webserver.

Can you please share your idea to resolve this problem

if(php_sapi_name() == 'cli') {// i got apache2handler
    $connector = new FilePrintConnector("php://stdout");
} else {
 throw new InvalidArgumentException("Argument passed to Escpos::__construct() must implement interface PrintConnector, null given.");
  }
Venkat
  • 1
  • 3

1 Answers1

0

As the question quotes a snippet of very familiar-looking code, I'm assuming that you are referring to mike42/escpos-php.

If so, you will need to choose a PrintConnector which works for your platform (Windows, Mac, Linux) and interface (USB, Serial, Samba share, CUPS). The correct way to initialize the driver will be system specific.

A table of supported combinations with links to example snippets appears in the README file.

As an example, if you have USB printer on Linux, it may appear as /dev/usb/lp0. Assuming your permissions are configured to allow the webserver user to access that file, the to send a basic receipt is linked in the README under Linux/USB:

<?php
require __DIR__ . '/vendor/autoload.php';
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
use Mike42\Escpos\Printer;
$connector = new FilePrintConnector("/dev/usb/lp0");
$printer = new Printer($connector);
$printer -> text("Hello World!\n");
$printer -> cut();
$printer -> close();

Aside: The snippet you've quoted is no longer in the code, but was an old feature to fall back on php:///stdout if you are on the command-line and have not specified a print connector.

mike42
  • 1,608
  • 14
  • 24