track total size of static array and Unit/Class/Func
[hiphop-php.git] / hphp / runtime / server / server.cpp
blob644f3091421752984590cd64c8812196de3a4f1c
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
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"
20 #include <signal.h>
22 ///////////////////////////////////////////////////////////////////////////////
23 // statics
25 namespace HPHP {
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,
39 uint16_t port,
40 int maxThreads,
41 int initThreads) {
42 return createServer(ServerOptions{address, port, maxThreads, initThreads});
45 ServerFactoryRegistry::ServerFactoryRegistry()
46 : m_lock(false) {
49 ServerFactoryRegistry *ServerFactoryRegistry::getInstance() {
50 static ServerFactoryRegistry singleton;
51 return &singleton;
54 ServerPtr ServerFactoryRegistry::createServer(const std::string &type,
55 const std::string &address,
56 uint16_t port,
57 int maxThreads,
58 int initThreads) {
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) {
66 Lock lock(m_lock);
67 auto ret = m_factories.insert(std::make_pair(name, factory));
68 if (!ret.second) {
69 throw ServerException("a factory already exists for server type \"%s\"",
70 name.c_str());
74 ServerFactoryPtr ServerFactoryRegistry::getFactory(const std::string &name) {
75 Lock lock(m_lock);
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());
86 return it->second;
89 ///////////////////////////////////////////////////////////////////////////////
91 ServerException::ServerException(const char *fmt, ...) {
92 va_list ap; va_start(ap, fmt); format(fmt, ap); va_end(ap);
95 ///////////////////////////////////////////////////////////////////////////////