/** * @action pingDatabase * @return bool Always true if database available and writeable */ function pingDatabaseAction() { $hostname = infraRequestUtils::getHostname(); $server = ApiServerPeer::retrieveByHostname($hostname); if (!$server) { $server = new ApiServer(); $server->setHostname($hostname); } $server->setUpdatedAt(time()); if (!$server->save()) { return false; } return true; }
<?php require_once '../phplib/ApiServer.php'; /** * Dispatches an HTTP request for data to an ApiServer instance. */ $server = new ApiServer(); $data = $server->handleDataRequest($_GET); echo json_encode($data);
$smd = $this->jsonrpc_server->getServiceMap(); // Return the SMD to the client evhttp_response_add_header($r, "Content-Type", "application/json"); return evhttp_response_set($smd, 200, "OK"); } else { // set custom request, since we have to get post data through another function $request = new EvHttp_Json_Request($r); $this->jsonrpc_server->setResponse(new Zend_Json_Server_Response()); $response = $this->jsonrpc_server->handle($request); unset($request); evhttp_response_add_header($r, "Content-Type", "application/json"); return evhttp_response_set($response->toJson(), 200, "OK"); } default: return evhttp_response_set("Invalid Protocol", 500, "Error"); } } catch (Exception $e) { return $e->__toString(); } } public function run() { event_init(); $this->httpd = evhttp_start($this->addr, $this->port); evhttp_set_gencb($this->httpd, array($this, 'processRequest')); echo "XML-RPC server started at http://{$this->addr}:{$this->port}/xmlrpc...\n"; event_dispatch(); } } $app = new ApiServer("0.0.0.0", 8080); $app->run();
/** * Adds an object to the instance pool. * * Propel keeps cached copies of objects in an instance pool when they are retrieved * from the database. In some cases -- especially when you override doSelect*() * methods in your stub classes -- you may need to explicitly add objects * to the cache in order to ensure that the same objects are always returned by doSelect*() * and retrieveByPK*() calls. * * @param ApiServer $value A ApiServer object. * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally). */ public static function addInstanceToPool(ApiServer $obj, $key = null) { if (Propel::isInstancePoolingEnabled()) { if ($key === null) { $key = (string) $obj->getId(); } if (isset(self::$instances[$key]) || count(self::$instances) < kConf::get('max_num_instances_in_pool')) { self::$instances[$key] = $obj; kMemoryManager::registerPeer('ApiServerPeer'); } } }