Take the 2-minute tour ×

I have this Zebra ZM400 Printer connected to the network ( And I am trying to push a content to this printer directly from PHP.

This is the idea and I am just stuck without any way to do this. I tried the file_put_contents('', $content) but with no success.

Would appreciate if anyone could please help me in sorting out this. Thank you :-)



I printed using the LPR Protocol. No need to install driver or anything. The LPR Printing Class for PHP 5 can be downloaded from here:


share|improve this question
What that means? –  Nirmal Sep 22 '10 at 4:11
Probably because not many people still use Zebra printers to print labels... –  Mitch Dempsey Sep 22 '10 at 4:12
@webdestroya - The printer is for an industrial barcoding solution and I think we are left with no better option for mass printing. –  Nirmal Sep 22 '10 at 4:15
@Mitch What do they use? It seems to me that Zebras actually still have a great deal of usage. –  pbreitenbach Jun 6 '12 at 3:34
add comment

7 Answers

up vote 2 down vote accepted

I'm pretty sure just pushing text content over a socket will not work at all.

You will need to print over lpr is my guess. Install a print server like CUPS and you can send it using that...

share|improve this answer
The printer has an internal print server. Does that mean sending the content is possible? Thanks. –  Nirmal Sep 22 '10 at 4:13
@Nirmal - A print server allows you to communicate using a print driver. Doing file_put_contents will never work. –  Mitch Dempsey Sep 22 '10 at 4:59
I don't have a machine to install Linux and CUPS. Just found that the internal Print Server accepts files over FTP. But the trouble is that it only allows active connections while PHP is trying to initiate a passive connection. I shall put up a separate question regarding that and post the link here. Thanks for your time! –  Nirmal Sep 22 '10 at 5:43
At last I used the LPR printing protocol supported by the printer. The LPR Printing class for PHP can be found here: phpclasses.org/package/… –  Nirmal Sep 24 '10 at 4:01
This is an old question, but for anyone reading this in the future, you can absolutely push content directly to the printer over sockets as long as the printer is on the network. All you need to know is the printer's IP address and its port (usually 9100 with Zebra printers). Zebra's support portal km.zebra.com has samples of this. In this case, you would likely want to use PHP's socket library to achieve the communication. Generally shouldn't be a need for extra libraries (LPR etc.) if you already have the device's native language! –  jason.zissman Apr 12 '13 at 2:48
add comment

I had a similar issue where I was using a java program to print to a zebra printer without a print driver, and wanted to recreate this using PHP. It was bugging me that I couldn't find the answer. Through some packet capturing with Wireshark comparing the two, I felt that it was possible. I finally stumbled into the solution (at least for me). This will print a label to a networked Zebra printer directly from a PHP page without the need for a driver.


/* Get the port for the service. */
$port = "9100";

/* Get the IP address for the target host. */
$host = "";

/* construct the label */
$mrn = "123456";
$registration_date = "03/13/2013";
$dob = "06/06/1976";
$gender = "M";
$nursing_station = "ED";
$room = "ED01";
$bed = "07";
$lastname = "Lastname";
$firstname = "Firstname";
$visit_id = "12345678";

$label = "q424\nN\n";
$label .= "A10,16,0,3,1,1,N,\"MR# " . $mrn . " ";
$label .= $registration_date . "\"\n";
$label .= "B10,43,0,3,2,4,50,N,\"" . $mrn . "\"\n";
$label .= "A235,63,0,3,1,1,N,\" ";
$label .= $dob . " ";
$label .= $gender . "\"\n";
$label .= "A265,85,0,3,1,1,N,\" ";
$label .= $nursing_station . " ";
$label .= $room . "-";
$label .= $bed . "\"\n";
$label .= "A10,108,0,3,1,1,N,\"";
$label .= $lastname . ",";
$label .= $firstname;
$label .= "\"\n";
$label .= "A10,135,0,3,1,1,N,\" #" . $visit_id . "\"\n";
$label .= "B10,162,0,3,2,4,50,N,\"" . $visit_id . "\"\n";
$label .= "P1\n";

$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket === false) {
    echo "socket_create() failed: reason: " . socket_strerror(socket_last_error    ()) . "\n";
} else {
    echo "OK.\n";

echo "Attempting to connect to '$host' on port '$port'...";
$result = socket_connect($socket, $host, $port);
if ($result === false) {
    echo "socket_connect() failed.\nReason: ($result) " . socket_strerror    (socket_last_error($socket)) . "\n";
} else {
    echo "OK.\n";

socket_write($socket, $label, strlen($label));

share|improve this answer
Different language (EPL instead of ZPL) but exactly what the original poster likely needed to see when the question was first asked. –  jason.zissman Apr 12 '13 at 2:50
+1 Thanks, Edwin. That was what I ended up doing, but long after accepting the original answer. Thanks for the input though! –  Nirmal May 15 '13 at 5:48
add comment


If you have access to the serial port:


 $fpi = fopen('/dev/ttyS0', 'r+');

$comando = "
A40,145,0,3,1,0,N,\"N.- $don \"
fwrite($fpi, $comando);


share|improve this answer
Thanks! Nothing is too late. This is perfect and is exactly what I did at a later stage. Works all the time and no too much fancy coding. –  Nirmal May 15 '13 at 5:54
I utilise this principal, in combination with str_replace on .prn template files (must use printer font) and use the shell_exec (or backtick operator) to run the 'lp -d printer file' –  elzaer Jun 19 '13 at 6:41
add comment

I see you've gotten solutions using LPR and FTP, but I'm almost certain the Zebra printers will accept raw ZPL text on port 9100.

share|improve this answer
add comment

I have created a file in zebra language and used FTP to send the file many times in the past. just save the file and then create an ftp connection to the printer then use the put command to send the .txt file. the printer will do the rest

share|improve this answer
add comment

There is sample code on how to send ZPL directly to Zebra printers at:


I didn't see any in PHP, but there is an example of talking directly to the printer via port 9100 using VB.

share|improve this answer
add comment

Take a look at these PHP printer functions

Note that

These functions are only available under Windows 9.x, ME, NT4 and 2000.

share|improve this answer
And you have to install a PECL package. –  NullUserException Sep 22 '10 at 4:20
I tried the php_printer.dll on PHP 5.3 and it creates a nightmare of 'Out of Memory' errors. You can read the whole thread here: spinics.net/lists/winphp/msg08651.html –  Nirmal Sep 22 '10 at 4:22
add comment

Your Answer


