Appserver.ioPHP 应用服务器
appserver.io 是一个多线程的 PHP 应用服务器,实现真正多线程的 PHP 编程,高效安全而且快速,速度比基于 Nginx 的 Magento 标准安装要快 50%。使用上非常像 Java 的 Servlet。
亮点:
-
使用 Doctrine 作为标准的持久层
-
Session Beans (stateful, stateless + singleton)
-
Message Beans
-
Timer Service (tbd)
-
Servlet Engine
-
Integrated Message Queue
-
Easy scaling
-
Webservices
要求:
-
PHP 5.4+ on x64 or x86
-
ZTS enabled (thread safety)
-
POSIX threads implementation
-
Memcached (2.1+)
示例配置:
<servlet> <description><![CDATA[A demo servlet]]></description> <display-name>DemoServlet</display-name> <servlet-name>DemoServlet</servlet-name> <servlet-class>\TechDivision\Example\Servlets\DemoServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>DemoServlet</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping>
示例代码:
public function doGet(Request $req, Response $res) { // build path to template $pathToTemplate = $this->getServletConfig()->getWebappPath() . DIRECTORY_SEPARATOR . 'static' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . 'layout.phtml'; // init template $template = new DemoTemplate($pathToTemplate); $baseUrl = '/'; // if the application has NOT been called over a //VHost configuration append application folder naem if (!$this->getServletConfig()->getApplication()->isVhostOf( $req->getServerName()) ) { $baseUrl .= $this->getServletConfig()->getApplication()->getName() . '/'; } // set vars in template $template->setBaseUrl($baseUrl); $template->setRequestUri($req->getUri()); $template->setUserAgent($req->getHeader("User-Agent")); $template->setWebappName($this->getServletConfig()->getApplication()->getName()); // set response content by render template $res->setContent($template->render()); }
评论