我有一台带TCP/IP端口的ZK F7考勤机,通过自带的软件返回数据。但我想通过 php 使用数组中的 php socket 收集考勤数据,然后将它们保存在 mysql 中。为此,我尝试了下面的代码,但出现错误(调用未定义的函数 socket_create())。错误的解决方法应该是什么?
<?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;
}
}
?>