2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 #include "hphp/runtime/server/server.h"
18 #include "hphp/runtime/server/satellite-server.h"
19 #include "hphp/runtime/base/preg.h"
22 ///////////////////////////////////////////////////////////////////////////////
26 ///////////////////////////////////////////////////////////////////////////////
28 bool Server::StackTraceOnError
= true;
29 ///////////////////////////////////////////////////////////////////////////////
31 Server::Server(const std::string
&address
, int port
)
32 : m_address(address
), m_port(port
),
33 m_urlChecker(SatelliteServerInfo::checkMainURL
) {
36 ///////////////////////////////////////////////////////////////////////////////
38 ServerPtr
ServerFactory::createServer(const std::string
&address
,
42 return createServer(ServerOptions
{address
, port
, maxThreads
, initThreads
});
45 ServerFactoryRegistry::ServerFactoryRegistry()
49 ServerFactoryRegistry
*ServerFactoryRegistry::getInstance() {
50 static ServerFactoryRegistry singleton
;
54 ServerPtr
ServerFactoryRegistry::createServer(const std::string
&type
,
55 const std::string
&address
,
59 auto factory
= getInstance()->getFactory(type
);
60 return factory
->createServer(
61 ServerOptions
{address
, port
, maxThreads
, initThreads
});
64 void ServerFactoryRegistry::registerFactory(const std::string
&name
,
65 const ServerFactoryPtr
&factory
) {
67 auto ret
= m_factories
.insert(std::make_pair(name
, factory
));
69 throw ServerException("a factory already exists for server type \"%s\"",
74 ServerFactoryPtr
ServerFactoryRegistry::getFactory(const std::string
&name
) {
76 auto it
= m_factories
.find(name
);
77 if (it
== m_factories
.end()) {
78 if (name
== "libevent") {
79 throw ServerException(
80 "HHVM no longer supports the built-in webserver as of 3.0.0. Please "
81 "use your own webserver (nginx or apache) talking to HHVM over "
82 "fastcgi. https://github.com/facebook/hhvm/wiki/FastCGI");
84 throw ServerException("no factory for server type \"%s\"", name
.c_str());
89 ///////////////////////////////////////////////////////////////////////////////
91 ServerException::ServerException(const char *fmt
, ...) {
92 va_list ap
; va_start(ap
, fmt
); format(fmt
, ap
); va_end(ap
);
95 ///////////////////////////////////////////////////////////////////////////////