Reputation: 41
I have a ZK F7 attendance machine with TCP/IP port which returns data through the software comes with it. But I want to collect attendance data through php using php socket in an array then save them in mysql. to do this I tried the code bellow but getting erro (call to undefined function socket_create()). what should be the solve of the error?
<?php
// Server IP address
$address = "192.168.1.201";
// Port to listen
$port = 4370;
$mysock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_bind($mysock,$address, $port) or die('Could not bind to address');
socket_listen($mysock, 5);
$client = socket_accept($mysock);
// read 1024 bytes from client
$input = socket_read($client, 1024);
// write received gprs data to the file
writeToFile('socketLog.txt', $input);
socket_close($client);
socket_close($mysock);
function writeToFile($strFilename, $strText) {
if($fp = @fopen($strFilename,"w")) {
$contents = fwrite($fp, $strText);
fclose($fp);
return true;
} else {
return false;
}
}
?>
Upvotes: 0
Views: 4557
Reputation: 467
Change the line
$mysock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
to
$mysock = socket_create(AF_INET, SOCK_DGRAM, 0);
And I guess that will fix it by using UDP to connect to the ZK device.
Upvotes: 0
Reputation: 711
You don't have php_sockets extension enabled. Go do that in php.ini
Upvotes: 1