// Port //$port = $dataPorta['valor']; $port = 7099; // Path to look for files with commands to send $command_path = "./var/www/sites/1/"; //$from_email = $dataEmail['valor']; $from_email = '*****@*****.**'; //mysql_close($cnx); $__server_listening = true; error_reporting(E_ALL); set_time_limit(0); ob_implicit_flush(); declare (ticks=1); ini_set('sendmail_from', $from_email); //printLog($fh, "become_daemon() in"); become_daemon(); //printLog($fh, "become_daemon() out"); /* nobody/nogroup, change to your host's uid/gid of the non-priv user ** Comment by Andrew - I could not get this to work, i commented it out the code still works fine but mine does not run as a priv user anyway.... uncommented for completeness */ //change_identity(65534, 65534); /* handle signals */ pcntl_signal(SIGTERM, 'sig_handler'); pcntl_signal(SIGINT, 'sig_handler'); pcntl_signal(SIGCHLD, 'sig_handler'); //printLog($fh, "pcntl_signal ok"); /* change this to your own host / port */ //printLog($fh, "server_loop in");
/* sequence number -> increment while toggle bit unchanged */ $nullref = NULL; /* we need a reference variable to NULL for select */ $lastpkt = ""; /* holds the last packet */ /* setup signal handlers */ pcntl_signal(SIGTERM, "sig_handler"); pcntl_signal(SIGHUP, "sig_handler"); pcntl_signal(SIGUSR1, "sig_handler"); register_shutdown_function('exit_handler'); /* enable some logging */ define_syslog_variables(); openlog("rc5lirccmd", LOG_PID | LOG_CONS, LOG_DAEMON); /* posix functions */ $fh = open_pid_file($pid_file); $pid = become_daemon(); fputs($fh, $pid); fclose($fh); /* create listen socket */ $socket = stream_socket_server("udp://" . $listen_addr . ":" . $listen_port, $errno, $errstr, STREAM_SERVER_BIND); if (!$socket) { die("{$errstr} ({$errno})"); } /* create output (LIRC) socket */ $clientsocket = stream_socket_client("tcp://" . $lirc_server . ":" . $lirc_port, $errno, $errstr, 30); if (!$clientsocket) { die("{$errstr} ({$errno})\n"); } /* create a array for the sockets - i need it for select */ $csarray = array($clientsocket); $sarray = array($socket);