Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

frankhosaka's avatar

PHP may print on HP Neverstop?

I used this code

<?php
$imprimir="Olá mundo!";
try {   
    $fp=pfsockopen("192.168.0.18", 9100);
    fputs($fp, $imprimir);
    fclose($fp);
    echo 'Sucesso!!';}
catch (Exception $e) {
    echo 'Problema: ',  $e->getMessage(), "\n";}

but it activates only the printer, it does not print anything.

Is there a hope for me?

0 likes
1 reply
LaryAI's avatar
Level 58

It's possible that the printer is not receiving the correct data format. Try converting the string to a format that the printer can understand, such as ZPL or EPL. You can also try sending a test print command to the printer to see if it responds. Here's an example of how to send a ZPL command to a printer:

<?php
$imprimir="^XA^FO50,50^ADN,36,20^FDHello World^FS^XZ";
try {   
    $fp=pfsockopen("192.168.0.18", 9100);
    fputs($fp, $imprimir);
    fclose($fp);
    echo 'Success!!';
} catch (Exception $e) {
    echo 'Problem: ',  $e->getMessage(), "\n";
}

This code sends a ZPL command to print "Hello World" on the printer. If this works, you can modify the command to print whatever you need.

Please or to participate in this conversation.