Download the PHP package 0mithun/php-zkteco without Composer
On this page you can find all versions of the php package 0mithun/php-zkteco. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download 0mithun/php-zkteco
More information about 0mithun/php-zkteco
Files in 0mithun/php-zkteco
Package php-zkteco
Short Description A PHP package for managing ZKTeco biometric devices with TCP and UDP protocol support.
License MIT
Homepage https://github.com/0mithun/php-zkteco
Informations about the package php-zkteco
PHP ZKTeco
A PHP library for interfacing with ZKTeco biometric attendance devices. Supports both TCP and UDP protocols for reliable communication with fingerprint attendance machines.
Features
- Dual Protocol Support: Works with both TCP and UDP connections
- User Management: Add, remove, and retrieve users from the device
- Attendance Logs: Fetch attendance records with optional filtering
- Real-Time Logs: 🆕 Listen for live attendance events as they happen
- Fingerprint Management: Get, set, and remove fingerprints
- Device Control: Enable/disable device, restart, shutdown, sleep/resume
- LCD Display: Write custom messages to device screen
- Voice Test: Play voice prompts on the device
- Laravel Integration: Auto-discovery service provider included
Requirements
- PHP >= 8.0
- PHP Sockets Extension (
ext-sockets)
Installation
Quick Start
TCPMUX HTTP CONNECT Proxy
Connect through a TCPMUX httpconnect multiplexer for subdomain-based routing. This allows multiple devices to share a single port, routed by subdomain.
Basic TCPMUX Usage
How TCPMUX Works
- Library connects to proxy server at
base_domain:tcpmux_port - Sends HTTP CONNECT request with target
subdomain.base_domain:device_port - Proxy routes the connection to the device based on subdomain
- After tunnel is established, ZKTeco protocol communicates through it
Connection Comparison
| Feature | Direct TCP/UDP | TCPMUX |
|---|---|---|
| Port per device | Required (e.g., 7001, 7002...) | Shared (e.g., 1337) |
| Routing | By port number | By subdomain |
| Scalability | Limited by ports | Unlimited subdomains |
Constructor Parameters
API Reference
Connection Methods
connect(): bool
Establishes connection to the ZKTeco device.
disconnect(): bool
Disconnects from the device.
ping(bool $throw = false): bool
Tests connectivity to the device.
Device Information Methods
vendorName(): string|false
Returns the device manufacturer name.
deviceName(): string|false
Returns the device model name.
deviceId(): string|false
Returns the device ID.
serialNumber(): string|false
Returns the device serial number.
version(): string|false
Returns the firmware version.
osVersion(): string|false
Returns the OS version.
platform(): string|false
Returns the platform information.
fmVersion(): string|false
Returns the firmware version number.
pinWidth(): string|false
Returns the PIN width setting.
workCode(): string|false
Returns the work code status.
ssr(): string|false
Returns the SSR (Self-Service Recorder) status.
faceFunctionOn(): string|false
Returns whether face recognition is enabled.
getMemoryInfo(): object|false
Returns device memory information.
Time Methods
getTime(): string|false
Returns the current device time.
setTime(string $time): bool
Sets the device time.
User Management Methods
getUsers(?callable $callback = null): array
Retrieves all registered users from the device.
setUser(int $uid, string|int $userid, string $name, string|int $password, int $role = 0, int $cardno = 0): bool
Adds or updates a user on the device.
Parameters:
$uid- Unique ID (1-65535)$userid- User ID string (max 9 chars)$name- User name (max 24 chars)$password- Password (max 8 chars)$role- Role: 0=User, 14=Admin (default: 0)$cardno- Card number (default: 0)
removeUser(int $uid): bool
Removes a user by UID.
deleteUsers(callable $callback): void
Removes users conditionally using a callback.
clearAllUsers(): bool
⚠️ Warning: Removes ALL users from the device.
clearAdminPriv(): bool
Removes admin privileges from all users.
Attendance Methods
getAttendances(?callable $callback = null): array
Retrieves attendance records from the device.
Attendance States:
0- Check In1- Check Out2- Break Out3- Break In4- OT In5- OT Out
clearAttendance(): bool
⚠️ Warning: Clears ALL attendance logs from the device.
getRealTimeLogs(callable $callback, int $timeout = 0): bool
🆕 Registers for real-time attendance events. When a user scans their fingerprint or enters credentials, the callback is called immediately with the log data.
Parameters:
$callback- Function called with each real-time log entry$timeout- Timeout in seconds (0 = infinite, default)
Note: This method blocks while listening for events. Use the $timeout parameter or run in a background process/worker.
getRealTimeEvents(callable $callback, int $events, int $timeout = 0): bool
🆕 v1.2.0 Registers for multiple real-time event types. This is a more comprehensive version of getRealTimeLogs() that supports all device events.
Supported Events (use Mithun\PhpZkteco\Libs\Services\Util constants):
| Constant | Value | Description |
|---|---|---|
EF_ATTLOG |
1 | Attendance log (user punch in/out) |
EF_FINGER |
2 | Fingerprint scanned |
EF_ENROLLUSER |
4 | User enrolled on device |
EF_ENROLLFINGER |
8 | Fingerprint enrolled |
EF_BUTTON |
16 | Button pressed on device |
EF_UNLOCK |
32 | Door unlocked |
EF_VERIFY |
128 | User verified |
EF_FPFTR |
256 | Fingerprint feature event |
EF_ALARM |
512 | Alarm triggered |
Parameters:
$callback- Function called with each event$events- Bitmask of events to listen for (combine with|)$timeout- Timeout in seconds (0 = infinite)
Event Data Structure:
All events include these base fields:
Plus event-specific fields:
| Event | Additional Fields |
|---|---|
EF_ATTLOG |
user_id, record_time, state |
EF_ENROLLUSER / EF_VERIFY |
user_id |
EF_FINGER / EF_ENROLLFINGER / EF_FPFTR |
user_id, finger_index |
EF_BUTTON |
button_id |
EF_UNLOCK |
door_id, unlock_type |
EF_ALARM |
alarm_type |
Fingerprint Methods
getFingerprint(int $uid): array|false
Retrieves fingerprint data for a user.
setFingerprint(int $uid, array $fingerprint): bool
Sets fingerprint data for a user.
removeFingerprint(int $uid, array $fingerIds): int
Removes specific fingerprints from a user.
Device Control Methods
disableDevice(): bool
Disables the device (prevents user interaction).
enableDevice(): bool
Re-enables the device.
shutdown(): bool
Powers off the device.
restart(): bool
Restarts the device.
sleep(): bool
Puts the device into sleep mode.
resume(): bool
Wakes the device from sleep mode.
Display & Audio Methods
writeLCD(string $message = 'Welcome ZkTeco'): bool
Displays a message on the device LCD screen.
clearLCD(): bool
Clears the LCD screen.
testVoice(int $index = 0): bool
Plays a voice prompt on the device.
Custom Data Methods
getDeviceData(string $key): string
Retrieves device configuration data.
setCustomData(string $key, mixed $value): bool
Sets custom data on the device.
getCustomData(string $key): string
Retrieves custom data from the device.
setPushCommKey(string $value): bool
Sets the push communication key (for iClock integration).
getPushCommKey(): string
Gets the push communication key.
Protocol Comparison
| Feature | TCP | UDP |
|---|---|---|
| Reliability | High | Medium |
| Speed | Slightly slower | Fast |
| Connection | Persistent | Connectionless |
| Large data transfer | Better | May have issues |
| Recommended for | Production | Local testing |
Error Handling
Laravel Usage
The package auto-registers its service provider. You can use it in your controllers or commands:
Debugging
Enable debug logging by defining constants before instantiation:
Contributing
Please see CONTRIBUTING for details.
Security
If you've found a security vulnerability, please email [email protected] instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.