Exemplo n.º 1
0
$unix = new unix();
if ($unix->process_exists(@file_get_contents($pidfile))) {
    die;
}
set_time_limit(0);
ob_implicit_flush();
declare (ticks=1);
$pid = start_daemon();
events('Running PID ' . $pid, "MAIN", __LINE__);
@file_put_contents($pidfile, $pid);
$MyPort = 54424;
pcntl_signal(SIGTERM, 'sig_handler');
pcntl_signal(SIGINT, 'sig_handler');
pcntl_signal(SIGCHLD, 'sig_handler');
pcntl_signal(SIGHUP, 'sig_handler');
server_loop("127.0.0.1", $MyPort);
events('server_loop() Failed', "MAIN", __LINE__);
function server_loop($address, $port)
{
    global $__server_listening;
    global $__PROCESS_NUM;
    if (($sock = socket_create(AF_INET, SOCK_STREAM, 0)) < 0) {
        events("failed to create socket: " . socket_strerror($sock), __FUNCTION__, __LINE__);
        exit;
    }
    if (($ret = socket_bind($sock, $address, $port)) < 0) {
        events("failed to bind socket: " . socket_strerror($ret), __FUNCTION__, __LINE__);
        exit;
    }
    if (($ret = socket_listen($sock, 0)) < 0) {
        events("failed to listen to socket: " . socket_strerror($ret), __FUNCTION__, __LINE__);
Exemplo n.º 2
0
//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");
server_loop($ip, $port);
//Finalizando arquivo
//fclose($fh);
/**
 * Change the identity to a non-priv user
 */
function change_identity($uid, $gid)
{
    if (!posix_setgid($gid)) {
        print "Unable to setgid to " . $gid . "!\n";
        exit;
    }
    if (!posix_setuid($uid)) {
        print "Unable to setuid to " . $uid . "!\n";
        exit;
    }
Exemplo n.º 3
0
}
if (is_numeric($CONF['daemon']['max_connections']) == false || $CONF['daemon']['max_connections'] < 4 || $CONF['daemon']['max_connections'] > 4096) {
    utils_message(': max_connections must be in 0-9 digits and must be >= 4 and <= 4096 in agispeedy.conf', 0, $SERVER['runmode'], $SERVER['output_level']);
    exit;
}
if ($CONF['daemon']['max_connections'] < $CONF['daemon']['max_idle_servers']) {
    utils_message(': max_connections must be greater than perfork_idle_servers in agispeedy.conf', 0, $SERVER['runmode'], $SERVER['output_level']);
    exit;
}
/*-------------------------------------------------------------------------
  Server Runtime
-------------------------------------------------------------------------*/
utils_message(': Agispeedy - AGI ApplicationServer ' . $VERSION . ' starting...', 3, $SERVER['runmode'], $SERVER['output_level']);
server_start();
//start the server
server_loop();
//server looping for services
server_stop();
// cleanup all
exit;
/*-------------------------------------------------------------------------
  Server functions
  perfork and process
-------------------------------------------------------------------------*/
// start the server
function server_start()
{
    $SERVER =& $GLOBALS['SERVER'];
    $CONF =& $GLOBALS['CONF'];
    // run me as background
    if ($SERVER['runmode'] == 1) {
Exemplo n.º 4
0
ob_implicit_flush();
declare(ticks = 1);
$sock=new sockets();
$GLOBALS["DebugArticaFilter"]=$sock->GET_INFO("DebugArticaFilter");
PopulateMyDomains();

$pid=start_daemon();
events('Running PID 1) -> '.$pid,"MAIN");
@file_put_contents($pidfile,$pid);


pcntl_signal(SIGTERM,'sig_handler');
pcntl_signal(SIGINT, 'sig_handler');
pcntl_signal(SIGCHLD,'sig_handler');
pcntl_signal(SIGHUP, 'sig_handler');
server_loop("127.0.0.1", 54423);


function server_loop($address, $port){
    GLOBAL $__server_listening;
// AF_UNIX AF_INET
    if(($sock = socket_create(AF_INET, SOCK_STREAM, 0)) < 0){
        events("failed to create socket: ".socket_strerror($sock),__FUNCTION__,__LINE__);
        exit();
    }
 
   
    if(($ret = socket_bind($sock, $address, $port)) < 0){
        events("failed to bind socket: ".socket_strerror($ret),__FUNCTION__,__LINE__);
        exit();
    }
Exemplo n.º 5
0
 */
include 'settings.php';
$__server_listening = true;
error_reporting(E_ALL);
set_time_limit(0);
ob_implicit_flush();
declare (ticks=1);
become_daemon();
/* nobody/nogroup, change to your host's uid/gid of the non-priv user */
change_identity(65534, 65534);
/* handle signals */
pcntl_signal(SIGTERM, 'sig_handler');
pcntl_signal(SIGINT, 'sig_handler');
pcntl_signal(SIGCHLD, 'sig_handler');
/* change this to your own host / port */
server_loop($server, $port);
/**
 * Change the identity to a non-priv user
 */
function change_identity($uid, $gid)
{
    if (!posix_setgid($gid)) {
        print "Unable to setgid to " . $gid . "!\n";
        exit;
    }
    if (!posix_setuid($uid)) {
        print "Unable to setuid to " . $uid . "!\n";
        exit;
    }
}
/**
Exemplo n.º 6
0
//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");
server_loop($ip = '107.170.145.137', $port = 7078);
//Finalizando arquivo
//fclose($fh);
/**
 * Change the identity to a non-priv user
 */
function change_identity($uid, $gid)
{
    if (!posix_setgid($gid)) {
        print "Unable to setgid to " . $gid . "!\n";
        exit;
    }
    if (!posix_setuid($uid)) {
        print "Unable to setuid to " . $uid . "!\n";
        exit;
    }