centra_srv.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. echo "end run_loop";
  22. }
  23. function fork_subprocess($count,$listen_fd)
  24. {
  25. if (($child = pcntl_fork()) === 0)
  26. {
  27. echo "pid = {$child} count = {$count} " . __LINE__ ."\r\n";
  28. search_work($listen_fd);
  29. exit();
  30. }
  31. elseif($child === -1)
  32. {
  33. echo "pid = {$child} count = {$count} " . __LINE__ ."\r\n";
  34. die('could not fork');
  35. }
  36. else
  37. {
  38. echo "pid = {$child} count = {$count} " . __LINE__ ."\r\n";
  39. $ret = pcntl_waitpid($child,$status,WNOHANG);
  40. if($ret == 0) {
  41. echo "spawn-fcgi: successful ret == 0 PID: {$child}\n" ;
  42. }
  43. elseif($ret == -1) {
  44. echo "spawn-fcgi: ret == 0 PID: {$child}\n" ;
  45. }
  46. else {
  47. echo "spawn-fcgi: ret == 0 child exited PID: {$child}.\n";
  48. }
  49. }
  50. }
  51. function remote_addr()
  52. {
  53. global $config;
  54. $host = $config['searcher']['host'];
  55. $port = $config['searcher']['port'];
  56. return "{$host}:{$port}";
  57. }
  58. $listen_fd = stream_socket_server (remote_addr(), $errno, $errstr);
  59. $addr = remote_addr();
  60. echo "remote addr = {$addr} fd={$listen_fd}";
  61. search_work($listen_fd);
  62. //$count = 1;
  63. //while ($count-- > 0) {
  64. // fork_subprocess($count,$listen_fd);
  65. //}