Print Laravel receipts from shared hosting
Laravel on shared hosting can still print. The host only makes HTTPS. The receipt printer stays in the shop behind the agent.
For Laravel apps on hosts that cannot open raw sockets
Overview
Shared hosting blocks raw sockets, printer devices, and often exec. It usually allows outbound HTTPS. That is the only network permission this integration needs. A job in a controller or a queued Laravel job curls the print API.
Do not try to open 192.168.x.x:9100 from the host. That address is the shop LAN, and opening it from the internet would be the wrong design even if the host allowed it.
Store the key in .env. printer_code can be a column on the shops table. Never put either in a Blade template.
Integration steps
- 01
Create an API key on the server
Use an API key (pb_live_…) in the process environment. Authorization is Bearer. Do not ship the key to browsers or mobile apps.
- 02
Install the agent beside the printer
Windows, macOS, or Linux. GET /v1/printers and keep the numeric code.
- 03
POST /v1/print-jobs
content_type is pdf or raw. Send exactly one of content (standard base64) or content_url.
- 04
Reuse the idempotency key on retry
A new key means a second physical print. HTTP 409 means the same key was reused with a different body.
- 05
Read the job before you tell the user
GET /v1/print-jobs/{id}. Paid plans can also receive print_job.completed and print_job.failed webhooks.
PHP
<?php
// Laravel: receipt from a controller or job
$payload = [
'printer_code' => (int) getenv('PRINTER_CODE'),
'content_type' => 'raw',
'content' => base64_encode($receipt),,
'copies' => 1,
];
$ch = curl_init('https://api.printbase.cloud/v1/print-jobs');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('PRINTBASE_API_KEY'),
'Content-Type: application/json',
'Idempotency-Key: ' . (string) $order->id,
],
CURLOPT_POSTFIELDS => json_encode($payload),
]);
$body = curl_exec($ch);
if (curl_getinfo($ch, CURLINFO_HTTP_CODE) >= 300) {
throw new RuntimeException($body);
}
$job = json_decode($body, true); // id, status=queued
Details for this setup
Http::withToken
Laravel's HTTP client is enough. The JSON matches the curl sample. The agent prints only what you send; it does not fetch the document from the platform for you.
Queues
A database queue on shared hosting can send the job after the response. The idempotency key must be the order id, because workers retry.
Questions
Will Forge or a VPS change the code?
No. The same POST works. You gain a queue supervisor, not a new API.
Can I use windows printing from PHP?
Not on the host. The agent does the Windows printing. The call is still POST /v1/print-jobs with a Bearer API key, and HTTP 201 means queued rather than printed.
The host's allow_url_fopen is off.
Use curl or Laravel's HTTP client, which uses curl or streams you enable. One of those is normally available.
How many receipts fit the free plan?
100 jobs a month on one computer. A busy shop will need a paid plan.
Free plan: 100 jobs a month on one computer, no card.