Hi i have a problem with syncronize data from my attendance machine to my webapp, i’m currently using Laravel 10 with PHP 8.1, the connection is successful but it returns an empty string, and heres my code
public function tarikDataAbsen(AttendanceMachineInformation $attendanceMachineInformation): JsonResponse
{
$ip = $attendanceMachineInformation->ip_address;
$port = $attendanceMachineInformation->port;
$key = $attendanceMachineInformation->key;
$connect = fsockopen($ip, $port, $errno, $errstr, 1);
dd($connect);
$buffer = "";
if ($connect) {
$soapRequest = "<GetAttLog><ArgComKey xsi:type="xsd:integer">" . $key . "</ArgComKey><Arg><PIN xsi:type="xsd:integer">All</PIN></Arg></GetAttLog>";
$newLine = "rn";
fwrite($connect, "POST /iWsService HTTP/1.0" . $newLine);
fwrite($connect, "Content-Type: text/xml" . $newLine);
fwrite($connect, "Content-Length: " . strlen($soapRequest) . $newLine . $newLine);
fwrite($connect, $soapRequest . $newLine);
while ($response = fgets($connect, 1024)) {
$buffer .= $response;
}
} else {
echo "Koneksi Gagal";
}
$buffer = $this->parseData($buffer, "<GetAttLogResponse>", "</GetAttLogResponse>");
// dd($buffer);
$buffer = explode("rn", $buffer);
$export = [];
for ($a = 0, $aMax = count($buffer); $a < $aMax; $a++) {
$data = $this->parseData($buffer[$a], "<Row>", "</Row>");
$export[$a]['pin'] = $this->parseData($data, "<PIN>", "</PIN>");
$export[$a]['waktu'] = $this->parseData($data, "<DateTime>", "</DateTime>");
$export[$a]['status'] = $this->parseData($data, "<Status>", "</Status>");
}
return response()->json($export);
}
private function parseData($data, $p1, $p2): string
{
$data = ' ' . $data;
$hasil = '';
$awal = strpos($data, $p1);
if ($awal != '') {
$akhir = strpos(strstr($data, $p1), $p2);
if ($akhir != '') {
$hasil = substr($data, ($awal + strlen($p1)), ($akhir - strlen($p1)));
}
}
return $hasil;
}
when i dd the $connect
and when i dd the fgets function it return false, somebody can help ? thanks.
I tried using ZKLib but it took to long to response