OLD | NEW |
1 <?php | 1 <?php |
2 $beaconFilename = "beacon" . (isset($_REQUEST['name']) ? $_REQUEST['name'] : "")
. ".txt"; | 2 require_once '../../resources/portabilityLayer.php'; |
3 $retries = isset($_REQUEST['retries']) ? (int)$_REQUEST['retries'] : -1; | 3 |
| 4 $beaconFilename = sys_get_temp_dir() . "/beacon" . (isset($_REQUEST['name']) ? $
_REQUEST['name'] : "") . ".txt"; |
| 5 |
| 6 $max_attempts = 700; |
| 7 $retries = isset($_REQUEST['retries']) ? (int)$_REQUEST['retries'] : $max_attemp
ts; |
4 while (!file_exists($beaconFilename) && $retries != 0) { | 8 while (!file_exists($beaconFilename) && $retries != 0) { |
5 usleep(10000); | 9 usleep(10000); |
6 # file_exists() caches results, we want to invalidate the cache. | 10 # file_exists() caches results, we want to invalidate the cache. |
7 clearstatcache(); | 11 clearstatcache(); |
8 $retries--; | 12 $retries--; |
9 } | 13 } |
10 | 14 |
11 header('Content-Type: text/plain'); | 15 header('Content-Type: text/plain'); |
12 header('Access-Control-Allow-Origin: *'); | 16 header('Access-Control-Allow-Origin: *'); |
13 if (file_exists($beaconFilename)) { | 17 if (file_exists($beaconFilename)) { |
14 echo "Beacon sent successfully\n"; | 18 $beaconFile = false; |
15 $beaconFile = fopen($beaconFilename, 'r'); | 19 if (is_readable($beaconFilename)) { |
16 while ($line = fgets($beaconFile)) { | 20 $beaconFile = fopen($beaconFilename, 'r'); |
17 $trimmed = trim($line); | |
18 if ($trimmed != "") | |
19 echo "$trimmed\n"; | |
20 } | 21 } |
21 fclose($beaconFile); | 22 if ($beaconFile) { |
22 unlink($beaconFilename); | 23 echo "Beacon sent successfully\n"; |
| 24 while ($line = fgets($beaconFile)) { |
| 25 $trimmed = trim($line); |
| 26 if ($trimmed != "") |
| 27 echo "$trimmed\n"; |
| 28 } |
| 29 fclose($beaconFile); |
| 30 unlink($beaconFilename); |
| 31 } else { |
| 32 echo "Beacon status not readable\n"; |
| 33 } |
23 } else { | 34 } else { |
24 echo "Beacon not sent\n"; | 35 echo "Beacon not sent\n"; |
25 } | 36 } |
26 ?> | 37 ?> |
OLD | NEW |