3 // get out master library for gaasd daemon
4 require_once("../lib/gaasdLib.php");
6 // first we want to fork into the background like all good daemons should
10 // uncomment this bit and comment the fork above to stop it going into the background
14 // we failed to fork, oh woe is me
16 // i am the parent, i shall leave
17 //echo "i am a parent, i leave\n";
20 // here is where i need to swithc to TCP network protocol stuff
21 // i must bind 127.0.0.1 though.
22 // what i want to happen is this:
23 // 1) server receives connection
24 // 2) server forks off process to process connection
25 // 3) main server continues.
26 // a forked process thingy should be fully self contained and capable of dealing
27 // with "problems", i.e. the parent doesnt want to have to clean up children
29 // Here goes the tcp equivalent
30 global $TCP_PORT_NUMBER;
31 $res = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
32 socket_bind($res, "127.0.0.1", $TCP_PORT_NUMBER);
36 $data_socket = socket_accept($res);
38 $forked = pcntl_fork();
40 // TODO: DEAL WITH THIS PROPERLY
42 echo "Failed to fork\n";
44 // I am the child, i process the request
45 // all the shit down below goes in here
49 $size = socket_recv($data_socket, $recvd_a, 1024, 0);
51 if(preg_match("/.*\:EOD$/", $recvd)) {
52 // we have a full string... break out
58 $xps = explode(":", $recvd);
59 $component = unserialize(base64_decode($xps[1]));
60 $msg_type = $component["type"];
61 $msg = $component["data"];
63 $data_returned = processMessage($msg_type, $msg);
65 $d_comp["type"] = $msg_type;
66 $d_comp["data"] = $data_returned;
68 $realdata_returning = "AS:".base64_encode(serialize($d_comp)).":EOD";
70 socket_send($data_socket, $realdata_returning, strlen($realdata_returning), 0);
71 socket_close($data_socket);
76 function processMessage($msg_type, $msg)
80 $function = $MESSAGES[$msg_type]."_server";
82 if(function_exists($function)) {
83 return $function($msg);
85 error_log("Call to undefined function! $function\n");