How to Integrate ZKTeco Biometric Devices with Laravel
By Taha Rafi · 2026-11-24 · 9 min read

ZKTeco biometric terminals (TX628, iClock, K-Series, uFace, SpeedFace, and similar) speak a proprietary binary protocol over TCP or UDP — not REST, not a documented public API. Most PHP libraries that claim to support them only wrap a small, read-only subset of that protocol. This guide covers what actually works in a Laravel application, using php-zkteco, the open-source library I maintain for exactly this problem.
Why this is harder than a typical API integration
A ZKTeco device doesn't expose an HTTP endpoint you can simply call. It listens on a TCP or UDP socket (commonly port 4370), expects a specific framing sequence for TCP (\x50\x50\x82\x7d), and — if a comm key / password is set on the device — requires a bitwise MakeKey authentication handshake before it will respond to anything. Get any of that wrong and the device simply doesn't answer; there's no helpful error message to debug against.
1. Install the library
composer require taha-rafi/php-zktecoIn Laravel 8–12, the service provider and ZKTeco facade are auto-discovered. Publish the config if you want to drive the connection from your .env file:
php artisan vendor:publish --tag=zkteco-config2. Connect and pull attendance
By default the library tries TCP first and falls back to UDP automatically — useful when you don't know (or can't control) how a given device on site is configured:
use TahaRafi\ZKTeco\ZKTeco;
use TahaRafi\ZKTeco\Constants;
$zk = new ZKTeco('192.168.1.201', 4370, commKey: 0, protocol: Constants::PROTOCOL_AUTO);
if ($zk->connectWithRetry(maxAttempts: 3, retryDelayMs: 500)) {
$users = $zk->getUsersStructured();
$logs = $zk->getAttendanceStructured(since: '2026-11-01 00:00:00');
$zk->disconnect();
}The since parameter matters in production: without it, every sync run re-fetches the device's entire log history, which gets slow once a terminal has accumulated tens of thousands of punches. A Laravel scheduled command that stores the last synced timestamp (in your own database, or via the library's built-in state_file cursor when posting attendance to a remote URL) keeps each run incremental.
3. Writing attendance back to the device (less common, but real)
Most libraries treat the device's attendance log as read-only. php-zkteco can also write a punch directly into the terminal's own internal storage — useful if your application is the system of record and the device should reflect it (for LCD feedback or a "thank you" voice prompt, for example):
$zk->markAttendance(
userId: '1',
state: Constants::ATT_STATE_CHECK_OUT,
timestamp: '2026-11-24 18:00:00',
verifyType: Constants::VERIFY_FINGERPRINT,
options: [
'write_to_device' => true,
'device_feedback' => true,
]
);4. Where this fits in a Laravel application
In practice, the socket communication belongs in its own service class, kept separate from your HRMS/payroll logic — the terminal gives you raw punches (user id, timestamp, verify type); shift matching, overnight/cross-midnight handling, and grace periods are a separate, application-specific layer on top. That separation is what let the Raad Enterprise ERP below reuse the same socket layer across a biometric attendance module and a completely different door-access feature, without duplicating the protocol-handling code.
Common failure modes
- Device doesn't respond at all: almost always a protocol mismatch (TCP vs UDP) or a firewall blocking port 4370 — try
Constants::PROTOCOL_AUTObefore assuming the device is offline. CMD_ACK_UNAUTHerrors: the device has a comm key/password set that your connection isn't passing — pass the correctcommKeyto the constructor.- Duplicate attendance records on every sync: missing the
sincefilter or cursor tracking described above.
Related services
- Biometric & Attendance Systems — ZKTeco biometric terminal integration, attendance sync, and shift logic.
- Laravel Backend Development — Laravel backends, REST API integrations, and ERP systems for business platforms.
Related case studies
Integrating a ZKTeco device into your own application?
Share your requirements and we'll discuss a practical scope, approach, and next steps.