Advertisement
Guest User

Untitled

a guest
Dec 2nd, 2019
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. #!/usr/bin/php
  2. <?php
  3. include '/opt/unetlab/html/includes/functions.php';
  4. $pid = pcntl_fork();
  5.  
  6. if ($pid == -1) {
  7. exit("Error forking...\n");
  8. }
  9.  
  10. if ($pid == 0) {
  11. $interval = 3600;
  12. sleep(10);
  13.  
  14. while (true) {
  15. $fp = fsockopen('127.0.0.1', 444, $errno, $errstr, 30);
  16. fwrite($fp, 'CL');
  17. $interval = fread($fp, 1024);
  18.  
  19. if ((int) $interval == 0) {
  20. exit();
  21. }
  22.  
  23. fclose($fp);
  24. sleep($interval);
  25. }
  26. }
  27.  
  28. $server = stream_socket_server('tcp://127.0.0.1:444', $errno, $errorMessage);
  29.  
  30. if ($server === false) {
  31. exit('Could not bind to socket: ' . $errorMessage);
  32. }
  33.  
  34. $local_expire = strtotime('now');
  35. $client_socks = array();
  36.  
  37. while (true) {
  38. $read_socks = $client_socks;
  39. $read_socks[] = $server;
  40.  
  41. if (!stream_select($read_socks, $write, $except, 86400)) {
  42. continue;
  43. }
  44.  
  45. if (in_array($server, $read_socks)) {
  46. $new_client = stream_socket_accept($server);
  47.  
  48. if ($new_client) {
  49. $client_socks[] = $new_client;
  50. }
  51.  
  52. unset($read_socks[array_search($server, $read_socks)]);
  53. }
  54.  
  55. foreach ($read_socks as $sock) {
  56. $data = fread($sock, 128);
  57.  
  58. if (!$data) {
  59. unset($client_socks[array_search($sock, $client_socks)]);
  60. @fclose($sock);
  61. ..........................................................
  62. ..........................
  63. ........
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement