centra_srv.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. define('BASE_ROOT_PATH',str_replace('\\','/',dirname(__FILE__)));
  3. require_once (BASE_ROOT_PATH . '/fooder.php');
  4. require_once (BASE_ROOT_PATH . '/helper/search/server.php');
  5. require_once (BASE_ROOT_PATH . '/helper/search/processor.php');
  6. require_once (BASE_ROOT_PATH . '/helper/search/event_handler.php');
  7. require_once(BASE_ROOT_PATH . '/helper/search/util.php');
  8. require_once(BASE_ROOT_PATH . '/helper/category_helper.php');
  9. require_once(BASE_ROOT_PATH . '/helper/search/searcher.php');
  10. require_once(BASE_ROOT_PATH . '/helper/category_helper.php');
  11. require_once(BASE_ROOT_PATH . '/helper/category_helper.php');
  12. require_once(BASE_ROOT_PATH . '/helper/algorithm.php');
  13. function search_work($sockfd)
  14. {
  15. echo "start searcher";
  16. Base::run_util();
  17. search\searcher::instance();
  18. search\CentraHelper::instance()->init(new search\processor());
  19. echo "start ending";
  20. search\CentraHelper::instance()->run_loop($sockfd);
  21. }
  22. function fork_subprocess($count,$listen_fd)
  23. {
  24. if (($child = pcntl_fork()) === 0)
  25. {
  26. echo "pid = {$child} count = {$count} " . __LINE__ ."\r\n";
  27. search_work($listen_fd);
  28. exit();
  29. }
  30. elseif($child === -1)
  31. {
  32. echo "pid = {$child} count = {$count} " . __LINE__ ."\r\n";
  33. die('could not fork');
  34. }
  35. else
  36. {
  37. echo "pid = {$child} count = {$count} " . __LINE__ ."\r\n";
  38. $ret = pcntl_waitpid($child,$status,WNOHANG);
  39. if($ret == 0) {
  40. echo "spawn-fcgi: successful ret == 0 PID: {$child}\n" ;
  41. }
  42. elseif($ret == -1) {
  43. echo "spawn-fcgi: ret == 0 PID: {$child}\n" ;
  44. }
  45. else {
  46. echo "spawn-fcgi: ret == 0 child exited PID: {$child}.\n";
  47. }
  48. }
  49. }
  50. function remote_addr()
  51. {
  52. global $config;
  53. $host = $config['searcher']['host'];
  54. $port = $config['searcher']['port'];
  55. return "{$host}:{$port}";
  56. }
  57. $listen_fd = stream_socket_server (remote_addr(), $errno, $errstr);
  58. //search_work($listen_fd);
  59. $count = 1;
  60. while ($count-- > 0) {
  61. fork_subprocess($count,$listen_fd);
  62. }