Appserver.io PHP 应用服务器 项目简介
appserver.io 是一个多线程的 PHP 应用服务器,实现真正多线程的 PHP 编程,高效安全而且快速,速度比基于 Nginx 的 Magento 标准安装要快 50%。使用上非常像 Java 的 Servlet。亮点:使用 Doctrine 作为标准的持久层Session Beans (stateful, stateless + singleton)Message BeansTimer Service (tbd)Servlet EngineIntegrated Message QueueEasy scalingWebservices要求:PHP 5.4+ on x64 or x86ZTS enabled (thread safety)POSIX threads implementationMemcached (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());
}
<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());
}