<?php
// Set the file path
$dataSendFilePath = 'data_send';
$dataRecvFilePath = 'data_recv';
// Check if the payload parameter is set
if (isset($_REQUEST['response'])) {
$response = $_REQUEST['response'];
file_put_contents($dataRecvFilePath, $response);
file_put_contents($dataSendFilePath, '');
die();
}
// Check if the "payload" parameter exists in the request
if (isset($_REQUEST['payload'])) {
// Get the payload value
$payload = $_REQUEST['payload'];
// Acquire an exclusive lock on the "data_send" file
$sendFile = fopen('data_send', 'w');
if (flock($sendFile, LOCK_EX)) {
// Write the payload to the "data_send" file
fwrite($sendFile, $payload);
// Release the lock and close the file
flock($sendFile, LOCK_UN);
fclose($sendFile);
} else {
// Failed to acquire the lock
die('Failed to write payload to data_send file.');
}
}
// Check if the "data_recv" file contains data
while (true) {
$dataRecv = file_get_contents('data_recv');
// Check if the file contains data
if (!empty($dataRecv)) {
// Display the data
echo $dataRecv;
file_put_contents($dataRecvFilePath, '');
file_put_contents($dataSendFilePath, '');
// Exit the loop
break;
}
// Wait for a second before checking again
sleep(1);
}
?>