title: PHP Printing to Remote Printer
body: <p>I have a remote POS printer it uses the ESC/POS protocol.
  I have a PHP app running that prints messages:</p>
  
  <pre><code>    $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)&lt;br /&gt;\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);
      }
  </code></pre>
  
  <p>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.  </p>