A mod_phix for apache is needed, although for async-io, FastCGI will need to be used as we can’t multiple conenctiosn itno a single VM with apache architecture.
The Phix engine has been designed to support non-blocking I/O from the core - this means that as logn as you don’t call any blockign functions, you can process all of your Phix web requests from a single VM even when you don’t want to write straight away. This is realy useful for AJAX style blockign requests commonly used for realtime notifications:
/* * This example * */ class MyWebApp implements INonBlockingWebService { private $requests = array(); /* * This method is called on every single request. If there is an 'ip' and 'msg' * GET parameter, then we send the contents of 'msg' to a connection from 'ip', otherwise * error with a HTTP 500 */ function onRequest($req) { if ($req->get->has(array('ip', 'msg'))) { if (!$this->onMyEvent($req->get['ip'], $req->get['msg'])) { $req-header('HTTP/1.0 500'); $req->print('No connection from this address'); } } else { $this->requests[$req->ip_address()] = $req; } } /* * Called when a request that has not been finished has become disconnected. */ function onDisconnect($req) { unset($this->requests[$req->ip]); } /* * */ function onMyEvent($ip) { if (array_key_exists($this->requests, $ip)) { $this->requests[$ip]->print('<somexml/>'); unset($this->requests[$ip]); return true; } return false; } }
Another concept that has been included in the phix core is that of continuations.
Continuations allow the program to pause execution at a cettian point, and wind up the whole stack + registers into an object for later continuation