Advertisement
Guest User

fetch

a guest
Feb 21st, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. <?php namespace OpenFuego;
  2.  
  3. use OpenFuego\lib\Logger as Logger;
  4.  
  5. if (!defined('PHP_VERSION_ID') || PHP_VERSION_ID < 50300) {
  6. die(__NAMESPACE__ . ' requires PHP 5.3.0 or higher.');
  7. }
  8.  
  9. if (php_sapi_name() != 'cli') {
  10. die('This script must be invoked from the command line.');
  11. }
  12.  
  13. require_once(__DIR__ . '/init.php');
  14.  
  15. if (!function_exists('pcntl_fork')) {
  16. $error_message = "\n"
  17. . 'To start OpenFuego, run these commands:'
  18. . "\n\n"
  19. . "\tnohup " . \PHP_BINDIR . '/php ' . BASE_DIR . '/collect.php > /dev/null 2> /dev/null & echo $!'
  20. . "\n"
  21. . "\tnohup " . \PHP_BINDIR . '/php ' . BASE_DIR . '/consume.php > /dev/null 2> /dev/null & echo $!'
  22. . "\n\n";
  23.  
  24. die($error_message);
  25. }
  26.  
  27. // Ignore hangup signal (when user exits shell)
  28. pcntl_signal(SIGHUP, SIG_IGN);
  29.  
  30. // Handle shutdown tasks
  31. pcntl_signal(SIGTERM, function() {
  32.  
  33. global $_should_stop;
  34. $_should_stop = TRUE;
  35.  
  36. Logger::info("Received shutdown request, finishing up.");
  37.  
  38. return;
  39. });
  40.  
  41. $pids = array();
  42.  
  43. $pids[0] = pcntl_fork();
  44.  
  45. if (!$pids[0]) {
  46. include_once(__DIR__ . '/collect.php');
  47. }
  48.  
  49. $pids[1] = pcntl_fork();
  50.  
  51. if (!$pids[1]) {
  52. include_once(__DIR__ . '/consume.php');
  53. }
  54.  
  55. echo __NAMESPACE__ . ' collector running as PID ' . $pids[0] . "\n";
  56. echo __NAMESPACE__ . ' consumer running as PID ' . $pids[1] . "\n";
  57.  
  58. @file_put_contents(\OpenFuego\TMP_DIR . '/OpenFuego-collect.pid', $pids[0]);
  59. @file_put_contents(\OpenFuego\TMP_DIR . '/OpenFuego-consume.pid', $pids[1]);
  60.  
  61. exit;
  62. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement