1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- <?php
- /**
- * Created by PhpStorm.
- * User: stanley-king
- * Date: 2017/12/14
- * Time: 上午11:53
- */
- define('BASE_ROOT_PATH',str_replace('\\','/',dirname(__FILE__)));
- require_once(BASE_ROOT_PATH . '/fooder.php');
- require_once(BASE_ROOT_PATH . '/helper/search/srv_base.php');
- require_once(BASE_ROOT_PATH . '/helper/room/room_server.php');
- require_once(BASE_ROOT_PATH . '/helper/room/room_processor.php');
- require_once(BASE_ROOT_PATH . '/helper/room/room_handler.php');
- require_once(BASE_ROOT_PATH . '/helper/room/proto_type.php');
- require_once(BASE_ROOT_PATH . '/helper/room/base_room.php');
- require_once(BASE_ROOT_PATH . '/helper/room/chatwo_room.php');
- require_once(BASE_ROOT_PATH . '/helper/room/group_room.php');
- require_once(BASE_ROOT_PATH . '/helper/room/bargain_room.php');
- require_once(BASE_ROOT_PATH . '/helper/room/factory.php');
- require_once(BASE_ROOT_PATH . '/helper/room/room_client.php');
- require_once(BASE_ROOT_PATH . '/helper/room/bargain_manager.php');
- function search_work($sockfd)
- {
- Base::run_util();
- room\room_server::instance()->init(new room\room_processor());
- room\room_server::instance()->run_loop($sockfd);
- }
- function fork_subprocess($count,$listen_fd)
- {
- if (($pid = pcntl_fork()) === 0)
- {
- //ob_end_clean(); // Discard the output buffer and close
- fclose(STDIN); // Close all of the standard
- fclose(STDOUT); // file descriptors as we
- fclose(STDERR); // are running as a daemon.
- Log::record("pid = {$pid} count = {$count} ",Log::DEBUG);
- search_work($listen_fd);
- exit();
- }
- elseif($pid === -1)
- {
- Log::record("pid = {$pid} count = {$count} ",Log::DEBUG);
- die('could not fork');
- }
- else
- {
- Log::record("pid = {$pid} count = {$count} ",Log::DEBUG);
- $ret = pcntl_waitpid($pid,$status,WNOHANG);
- if($ret == 0) {
- Log::record("spawn-fcgi: successful ret == 0 PID: {$pid}",Log::DEBUG);
- }
- elseif($ret == -1) {
- Log::record("spawn-fcgi: ret == 0 PID: {$pid}",Log::DEBUG);
- }
- else {
- Log::record("spawn-fcgi: ret == 0 child exited PID: {$pid}.",Log::DEBUG);
- }
- }
- }
- function remote_addr()
- {
- global $config;
- $host = $config['room_srv']['host'];
- $port = $config['room_srv']['port'];
- return "{$host}:{$port}";
- }
- $listen_fd = stream_socket_server (remote_addr(), $errno, $errstr);
- if($listen_fd == false) {
- echo "无法创建socket,请退出之前进程.\n";
- }
- $count = 1;
- while ($count-- > 0) {
- fork_subprocess($count,$listen_fd);
- }
- //search_work($listen_fd);
|