Reduce JitPGOThreshold to 4
[hiphop-php.git] / hphp / runtime / base / runtime-option.cpp
blob326e9f9acedd514e33d77ef88cdad869c4b64d7e
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-2013 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/base/runtime-option.h"
19 // Get SIZE_MAX definition. Do this before including any more files, to make
20 // sure that this is the first place that stdint.h is included.
21 #ifndef __STDC_LIMIT_MACROS
22 #define __STDC_LIMIT_MACROS
23 #endif
24 #define __STDC_LIMIT_MACROS
25 #include <stdint.h>
26 #include <limits>
28 #include "hphp/runtime/base/type-conversions.h"
29 #include "hphp/runtime/base/builtin-functions.h"
30 #include "hphp/runtime/base/shared-store-base.h"
31 #include "hphp/runtime/server/access-log.h"
32 #include "hphp/runtime/base/extended-logger.h"
33 #include "hphp/runtime/base/simple-counter.h"
34 #include "hphp/runtime/base/memory-manager.h"
35 #include "hphp/util/util.h"
36 #include "hphp/util/network.h"
37 #include "hphp/util/logger.h"
38 #include "hphp/util/stack-trace.h"
39 #include "hphp/util/process.h"
40 #include "hphp/util/file-cache.h"
41 #include "hphp/runtime/base/hardware-counter.h"
42 #include "hphp/runtime/base/preg.h"
43 #include "hphp/parser/scanner.h"
44 #include "hphp/runtime/server/access-log.h"
45 #include "hphp/runtime/base/crash-reporter.h"
46 #include "folly/String.h"
48 namespace HPHP {
49 ///////////////////////////////////////////////////////////////////////////////
51 bool RuntimeOption::Loaded = false;
53 const char *RuntimeOption::ExecutionMode = "";
54 std::string RuntimeOption::BuildId;
55 std::string RuntimeOption::InstanceId;
56 std::string RuntimeOption::PidFile = "www.pid";
58 std::string RuntimeOption::LogFile;
59 std::string RuntimeOption::LogFileSymLink;
60 int RuntimeOption::LogHeaderMangle;
61 bool RuntimeOption::AlwaysEscapeLog = false;
62 bool RuntimeOption::AlwaysLogUnhandledExceptions = true;
63 bool RuntimeOption::InjectedStackTrace = true;
64 int RuntimeOption::InjectedStackTraceLimit = -1;
65 bool RuntimeOption::NoSilencer = false;
66 bool RuntimeOption::EnableApplicationLog = true;
67 bool RuntimeOption::CallUserHandlerOnFatals = true;
68 bool RuntimeOption::ThrowExceptionOnBadMethodCall = true;
69 int RuntimeOption::RuntimeErrorReportingLevel =
70 static_cast<int>(ErrorConstants::ErrorModes::HPHP_ALL);
72 std::string RuntimeOption::ServerUser;
74 int RuntimeOption::MaxLoopCount = 0;
75 int RuntimeOption::MaxSerializedStringSize = 64 * 1024 * 1024; // 64MB
76 bool RuntimeOption::NoInfiniteRecursionDetection = false;
77 bool RuntimeOption::ThrowBadTypeExceptions = false;
78 bool RuntimeOption::ThrowTooManyArguments = false;
79 bool RuntimeOption::WarnTooManyArguments = false;
80 bool RuntimeOption::ThrowMissingArguments = false;
81 bool RuntimeOption::ThrowInvalidArguments = false;
82 bool RuntimeOption::EnableHipHopErrors = true;
83 bool RuntimeOption::AssertActive = false;
84 bool RuntimeOption::AssertWarning = false;
85 int RuntimeOption::NoticeFrequency = 1;
86 int RuntimeOption::WarningFrequency = 1;
87 int64_t RuntimeOption::SerializationSizeLimit = StringData::MaxSize;
88 int64_t RuntimeOption::StringOffsetLimit = 10 * 1024 * 1024; // 10MB
90 std::string RuntimeOption::AccessLogDefaultFormat;
91 std::vector<AccessLogFileData> RuntimeOption::AccessLogs;
93 std::string RuntimeOption::AdminLogFormat;
94 std::string RuntimeOption::AdminLogFile;
95 std::string RuntimeOption::AdminLogSymLink;
98 std::string RuntimeOption::Tier;
99 std::string RuntimeOption::Host;
100 std::string RuntimeOption::DefaultServerNameSuffix;
101 std::string RuntimeOption::ServerType = "libevent";
102 std::string RuntimeOption::ServerIP;
103 std::string RuntimeOption::ServerPrimaryIP;
104 int RuntimeOption::ServerPort;
105 int RuntimeOption::ServerPortFd = -1;
106 int RuntimeOption::ServerBacklog = 128;
107 int RuntimeOption::ServerConnectionLimit = 0;
108 int RuntimeOption::ServerThreadCount = 50;
109 bool RuntimeOption::ServerThreadRoundRobin = false;
110 constexpr int kDefaultWarmupThrottleRequestCount = 0;
111 int RuntimeOption::ServerWarmupThrottleRequestCount =
112 kDefaultWarmupThrottleRequestCount;
113 int RuntimeOption::ServerThreadDropCacheTimeoutSeconds = 0;
114 int RuntimeOption::ServerThreadJobLIFOSwitchThreshold = INT_MAX;
115 int RuntimeOption::ServerThreadJobMaxQueuingMilliSeconds = -1;
116 bool RuntimeOption::ServerThreadDropStack = false;
117 bool RuntimeOption::ServerHttpSafeMode = false;
118 bool RuntimeOption::ServerStatCache = true;
119 std::vector<std::string> RuntimeOption::ServerWarmupRequests;
120 boost::container::flat_set<std::string>
121 RuntimeOption::ServerHighPriorityEndPoints;
122 int RuntimeOption::PageletServerThreadCount = 0;
123 bool RuntimeOption::PageletServerThreadRoundRobin = false;
124 int RuntimeOption::PageletServerThreadDropCacheTimeoutSeconds = 0;
125 int RuntimeOption::PageletServerQueueLimit = 0;
126 bool RuntimeOption::PageletServerThreadDropStack = false;
127 int RuntimeOption::FiberCount = 1;
128 int RuntimeOption::RequestTimeoutSeconds = 0;
129 int RuntimeOption::PspTimeoutSeconds = 0;
130 size_t RuntimeOption::ServerMemoryHeadRoom = 0;
131 int64_t RuntimeOption::RequestMemoryMaxBytes =
132 std::numeric_limits<int64_t>::max();
133 int64_t RuntimeOption::ImageMemoryMaxBytes = 0;
134 int RuntimeOption::ResponseQueueCount;
135 int RuntimeOption::ServerGracefulShutdownWait;
136 bool RuntimeOption::ServerHarshShutdown = true;
137 bool RuntimeOption::ServerEvilShutdown = true;
138 int RuntimeOption::ServerDanglingWait;
139 int RuntimeOption::ServerShutdownListenWait = 0;
140 int RuntimeOption::ServerShutdownListenNoWork = -1;
141 int RuntimeOption::GzipCompressionLevel = 3;
142 std::string RuntimeOption::ForceCompressionURL;
143 std::string RuntimeOption::ForceCompressionCookie;
144 std::string RuntimeOption::ForceCompressionParam;
145 bool RuntimeOption::EnableMagicQuotesGpc = false;
146 bool RuntimeOption::EnableKeepAlive = true;
147 bool RuntimeOption::ExposeHPHP = true;
148 bool RuntimeOption::ExposeXFBServer = false;
149 bool RuntimeOption::ExposeXFBDebug = false;
150 std::string RuntimeOption::XFBDebugSSLKey;
151 int RuntimeOption::ConnectionTimeoutSeconds = -1;
152 bool RuntimeOption::EnableOutputBuffering = false;
153 std::string RuntimeOption::OutputHandler;
154 bool RuntimeOption::ImplicitFlush = false;
155 bool RuntimeOption::EnableEarlyFlush = true;
156 bool RuntimeOption::ForceChunkedEncoding = false;
157 int64_t RuntimeOption::MaxPostSize;
158 bool RuntimeOption::AlwaysPopulateRawPostData = true;
159 int64_t RuntimeOption::UploadMaxFileSize;
160 std::string RuntimeOption::UploadTmpDir;
161 bool RuntimeOption::EnableFileUploads;
162 bool RuntimeOption::EnableUploadProgress;
163 int RuntimeOption::Rfc1867Freq;
164 std::string RuntimeOption::Rfc1867Prefix;
165 std::string RuntimeOption::Rfc1867Name;
166 bool RuntimeOption::LibEventSyncSend = true;
167 bool RuntimeOption::ExpiresActive = true;
168 int RuntimeOption::ExpiresDefault = 2592000;
169 std::string RuntimeOption::DefaultCharsetName = "utf-8";
170 bool RuntimeOption::ForceServerNameToHeader = false;
171 bool RuntimeOption::EnableCufAsync = false;
173 int RuntimeOption::RequestBodyReadLimit = -1;
175 bool RuntimeOption::EnableSSL = false;
176 int RuntimeOption::SSLPort = 443;
177 int RuntimeOption::SSLPortFd = -1;
178 std::string RuntimeOption::SSLCertificateFile;
179 std::string RuntimeOption::SSLCertificateKeyFile;
180 std::string RuntimeOption::SSLCertificateDir;
181 bool RuntimeOption::TLSDisableTLS1_2;
182 std::string RuntimeOption::TLSClientCipherSpec;
184 VirtualHostPtrVec RuntimeOption::VirtualHosts;
185 IpBlockMapPtr RuntimeOption::IpBlocks;
186 SatelliteServerInfoPtrVec RuntimeOption::SatelliteServerInfos;
188 int RuntimeOption::XboxServerThreadCount = 10;
189 int RuntimeOption::XboxServerMaxQueueLength = INT_MAX;
190 int RuntimeOption::XboxServerPort = 0;
191 int RuntimeOption::XboxDefaultLocalTimeoutMilliSeconds = 500;
192 int RuntimeOption::XboxDefaultRemoteTimeoutSeconds = 5;
193 int RuntimeOption::XboxServerInfoMaxRequest = 500;
194 int RuntimeOption::XboxServerInfoDuration = 120;
195 std::string RuntimeOption::XboxServerInfoWarmupDoc;
196 std::string RuntimeOption::XboxServerInfoReqInitFunc;
197 std::string RuntimeOption::XboxServerInfoReqInitDoc;
198 bool RuntimeOption::XboxServerInfoAlwaysReset = false;
199 bool RuntimeOption::XboxServerLogInfo = false;
200 std::string RuntimeOption::XboxProcessMessageFunc = "xbox_process_message";
201 std::string RuntimeOption::XboxPassword;
202 std::set<std::string> RuntimeOption::XboxPasswords;
204 std::string RuntimeOption::SourceRoot = Process::GetCurrentDirectory() + '/';
205 std::vector<std::string> RuntimeOption::IncludeSearchPaths;
206 std::string RuntimeOption::FileCache;
207 std::string RuntimeOption::DefaultDocument;
208 std::string RuntimeOption::ErrorDocument404;
209 bool RuntimeOption::ForbiddenAs404 = false;
210 std::string RuntimeOption::ErrorDocument500;
211 std::string RuntimeOption::FatalErrorMessage;
212 std::string RuntimeOption::FontPath;
213 bool RuntimeOption::EnableStaticContentCache = true;
214 bool RuntimeOption::EnableStaticContentFromDisk = true;
215 bool RuntimeOption::EnableOnDemandUncompress = true;
216 bool RuntimeOption::EnableStaticContentMMap = true;
218 bool RuntimeOption::Utf8izeReplace = true;
220 std::string RuntimeOption::StartupDocument;
221 std::string RuntimeOption::WarmupDocument;
222 std::string RuntimeOption::RequestInitFunction;
223 std::string RuntimeOption::RequestInitDocument;
224 std::vector<std::string> RuntimeOption::ThreadDocuments;
225 std::vector<std::string> RuntimeOption::ThreadLoopDocuments;
227 bool RuntimeOption::SafeFileAccess = false;
228 std::vector<std::string> RuntimeOption::AllowedDirectories;
229 std::set<std::string> RuntimeOption::AllowedFiles;
230 hphp_string_imap<std::string> RuntimeOption::StaticFileExtensions;
231 hphp_string_imap<std::string> RuntimeOption::PhpFileExtensions;
232 std::set<std::string> RuntimeOption::ForbiddenFileExtensions;
233 std::set<std::string> RuntimeOption::StaticFileGenerators;
234 FilesMatchPtrVec RuntimeOption::FilesMatches;
236 bool RuntimeOption::WhitelistExec = false;
237 bool RuntimeOption::WhitelistExecWarningOnly = false;
238 std::vector<std::string> RuntimeOption::AllowedExecCmds;
240 bool RuntimeOption::UnserializationWhitelistCheck = false;
241 bool RuntimeOption::UnserializationWhitelistCheckWarningOnly = true;
243 std::string RuntimeOption::TakeoverFilename;
244 int RuntimeOption::AdminServerPort;
245 int RuntimeOption::AdminThreadCount = 1;
246 std::string RuntimeOption::AdminPassword;
247 std::set<std::string> RuntimeOption::AdminPasswords;
249 std::string RuntimeOption::ProxyOrigin;
250 int RuntimeOption::ProxyRetry = 3;
251 bool RuntimeOption::UseServeURLs;
252 std::set<std::string> RuntimeOption::ServeURLs;
253 bool RuntimeOption::UseProxyURLs;
254 int RuntimeOption::ProxyPercentage = 0;
255 std::set<std::string> RuntimeOption::ProxyURLs;
256 std::vector<std::string> RuntimeOption::ProxyPatterns;
257 bool RuntimeOption::AlwaysUseRelativePath = false;
258 std::string RuntimeOption::IniFile = "/etc/hhvm/php.ini";
260 int RuntimeOption::HttpDefaultTimeout = 30;
261 int RuntimeOption::HttpSlowQueryThreshold = 5000; // ms
263 bool RuntimeOption::TranslateLeakStackTrace = false;
264 bool RuntimeOption::NativeStackTrace = false;
265 bool RuntimeOption::FullBacktrace = false;
266 bool RuntimeOption::ServerStackTrace = false;
267 bool RuntimeOption::ServerErrorMessage = false;
268 bool RuntimeOption::TranslateSource = false;
269 bool RuntimeOption::RecordInput = false;
270 bool RuntimeOption::ClearInputOnSuccess = true;
271 std::string RuntimeOption::ProfilerOutputDir;
272 std::string RuntimeOption::CoreDumpEmail;
273 bool RuntimeOption::CoreDumpReport = true;
274 std::string RuntimeOption::CoreDumpReportDirectory
275 #if defined(HPHP_OSS)
276 ("/tmp");
277 #else
278 ("/var/tmp/cores");
279 #endif
280 bool RuntimeOption::LocalMemcache = false;
281 bool RuntimeOption::MemcacheReadOnly = false;
283 bool RuntimeOption::EnableStats = false;
284 bool RuntimeOption::EnableWebStats = false;
285 bool RuntimeOption::EnableMemoryStats = false;
286 bool RuntimeOption::EnableAPCStats = false;
287 bool RuntimeOption::EnableAPCKeyStats = false;
288 bool RuntimeOption::EnableMemcacheStats = false;
289 bool RuntimeOption::EnableMemcacheKeyStats = false;
290 bool RuntimeOption::EnableSQLStats = false;
291 bool RuntimeOption::EnableSQLTableStats = false;
292 bool RuntimeOption::EnableNetworkIOStatus = false;
293 std::string RuntimeOption::StatsXSL;
294 std::string RuntimeOption::StatsXSLProxy;
295 int RuntimeOption::StatsSlotDuration = 10 * 60; // 10 minutes
296 int RuntimeOption::StatsMaxSlot = 12 * 6; // 12 hours
298 bool RuntimeOption::EnableAPCSizeStats = false;
299 bool RuntimeOption::EnableAPCSizeGroup = false;
300 std::vector<std::string> RuntimeOption::APCSizeSpecialPrefix;
301 std::vector<std::string> RuntimeOption::APCSizePrefixReplace;
302 std::vector<std::string> RuntimeOption::APCSizeSpecialMiddle;
303 std::vector<std::string> RuntimeOption::APCSizeMiddleReplace;
304 std::vector<std::string> RuntimeOption::APCSizeSkipPrefix;
305 bool RuntimeOption::EnableAPCSizeDetail = false;
306 bool RuntimeOption::EnableAPCFetchStats = false;
307 bool RuntimeOption::APCSizeCountPrime = false;
309 int64_t RuntimeOption::MaxRSS = 0;
310 int64_t RuntimeOption::MaxRSSPollingCycle = 0;
311 int64_t RuntimeOption::DropCacheCycle = 0;
312 int64_t RuntimeOption::MaxSQLRowCount = 10000;
313 int64_t RuntimeOption::MaxMemcacheKeyCount = 0;
314 int RuntimeOption::SocketDefaultTimeout = 5;
315 bool RuntimeOption::LockCodeMemory = false;
316 int RuntimeOption::MaxArrayChain = INT_MAX;
317 bool RuntimeOption::WarnOnCollectionToArray = false;
318 bool RuntimeOption::UseDirectCopy = false;
320 bool RuntimeOption::EnableDnsCache = false;
321 int RuntimeOption::DnsCacheTTL = 10 * 60; // 10 minutes
322 time_t RuntimeOption::DnsCacheKeyMaturityThreshold = 20;
323 size_t RuntimeOption::DnsCacheMaximumCapacity = 0;
324 int RuntimeOption::DnsCacheKeyFrequencyUpdatePeriod = 1000;
326 std::map<std::string, std::string> RuntimeOption::ServerVariables;
327 std::map<std::string, std::string> RuntimeOption::EnvVariables;
329 std::string RuntimeOption::LightProcessFilePrefix;
330 int RuntimeOption::LightProcessCount;
332 bool RuntimeOption::EnableHipHopSyntax = false;
333 bool RuntimeOption::EnableHipHopExperimentalSyntax = false;
334 bool RuntimeOption::EnableShortTags = true;
335 bool RuntimeOption::EnableAspTags = false;
336 bool RuntimeOption::EnableXHP = false;
337 bool RuntimeOption::EnableObjDestructCall = false;
338 bool RuntimeOption::EnableEmitSwitch = true;
339 bool RuntimeOption::EnableEmitterStats = true;
340 bool RuntimeOption::EnableInstructionCounts = false;
341 bool RuntimeOption::CheckSymLink = true;
342 int RuntimeOption::MaxUserFunctionId = (2 * 65536);
343 bool RuntimeOption::EnableArgsInBacktraces = true;
344 bool RuntimeOption::EnableZendCompat = false;
345 bool RuntimeOption::TimeoutsUseWallTime = true;
347 int RuntimeOption::GetScannerType() {
348 int type = 0;
349 if (EnableShortTags) type |= Scanner::AllowShortTags;
350 if (EnableAspTags) type |= Scanner::AllowAspTags;
351 if (EnableXHP) type |= Scanner::AllowXHPSyntax;
352 if (EnableHipHopSyntax) type |= Scanner::AllowHipHopSyntax;
353 return type;
356 // Initializers for Eval flags.
357 static inline bool evalJitDefault() {
358 // --mode server or --mode daemon
359 // run long enough to justify JIT
360 if (RuntimeOption::ServerExecutionMode()) {
361 return true;
364 // JIT explicitly turned on via .hhvm-jit file
365 static const char* path = "/.hhvm-jit";
366 struct stat dummy;
367 return stat(path, &dummy) == 0;
370 static inline std::string regionSelectorDefault() {
371 #ifdef HHVM_REGION_SELECTOR_TRACELET
372 return "tracelet";
373 #else
374 #ifdef HHVM_REGION_SELECTOR_LEGACY
375 return "legacy";
376 #else
377 #ifdef HHVM_REGION_SELECTOR_HOTTRACE
378 return "hottrace";
379 #else
380 return "";
381 #endif
382 #endif
383 #endif
386 static inline bool pgoDefault() {
387 #ifdef HHVM_REGION_SELECTOR_HOTTRACE
388 return true;
389 #else
390 return false;
391 #endif
394 static inline bool hhirRelaxGuardsDefault() {
395 return RuntimeOption::EvalJitRegionSelector == "tracelet";
398 static inline bool hhbcRelaxGuardsDefault() {
399 return !RuntimeOption::EvalHHIRRelaxGuards;
402 static inline bool simulateARMDefault() {
403 #ifdef HHVM_SIMULATE_ARM_BY_DEFAULT
404 return true;
405 #else
406 return false;
407 #endif
410 static inline bool xlsDefault() {
411 return RuntimeOption::EvalSimulateARM;
414 static inline bool hugePagesSoundNice() {
415 return RuntimeOption::ServerExecutionMode();
418 const uint64_t kEvalVMStackElmsDefault =
419 #ifdef VALGRIND
420 0x800
421 #else
422 0x4000
423 #endif
425 const uint32_t kEvalVMInitialGlobalTableSizeDefault = 512;
426 static const int kDefaultWarmupRequests = debug ? 1 : 11;
427 static const int kDefaultJitPGOThreshold = debug ? 2 : 4;
428 static const size_t kJitGlobalDataDef = RuntimeOption::EvalJitASize >> 2;
429 inline size_t maxUsageDef() {
430 return RuntimeOption::EvalJitASize;
432 #define F(type, name, def) \
433 type RuntimeOption::Eval ## name = type(def);
434 EVALFLAGS();
435 #undef F
436 std::set<string, stdltistr> RuntimeOption::DynamicInvokeFunctions;
437 bool RuntimeOption::RecordCodeCoverage = false;
438 std::string RuntimeOption::CodeCoverageOutputFile;
440 std::string RuntimeOption::RepoLocalMode;
441 std::string RuntimeOption::RepoLocalPath;
442 std::string RuntimeOption::RepoCentralPath;
443 std::string RuntimeOption::RepoEvalMode;
444 std::string RuntimeOption::RepoJournal;
445 bool RuntimeOption::RepoCommit = true;
446 bool RuntimeOption::RepoDebugInfo = true;
447 // Missing: RuntimeOption::RepoAuthoritative's physical location is
448 // perf-sensitive.
450 bool RuntimeOption::SandboxMode = false;
451 std::string RuntimeOption::SandboxPattern;
452 std::string RuntimeOption::SandboxHome;
453 std::string RuntimeOption::SandboxFallback;
454 std::string RuntimeOption::SandboxConfFile;
455 std::map<std::string, std::string> RuntimeOption::SandboxServerVariables;
456 bool RuntimeOption::SandboxFromCommonRoot;
457 std::string RuntimeOption::SandboxDirectoriesRoot;
458 std::string RuntimeOption::SandboxLogsRoot;
460 bool RuntimeOption::EnableDebugger = false;
461 bool RuntimeOption::EnableDebuggerColor = true;
462 bool RuntimeOption::EnableDebuggerPrompt = true;
463 bool RuntimeOption::EnableDebuggerServer = false;
464 bool RuntimeOption::EnableDebuggerUsageLog = false;
465 bool RuntimeOption::DebuggerDisableIPv6 = false;
466 int RuntimeOption::DebuggerServerPort = 8089;
467 int RuntimeOption::DebuggerDefaultRpcPort = 8083;
468 std::string RuntimeOption::DebuggerDefaultRpcAuth;
469 std::string RuntimeOption::DebuggerRpcHostDomain;
470 int RuntimeOption::DebuggerDefaultRpcTimeout = 30;
471 std::string RuntimeOption::DebuggerDefaultSandboxPath;
472 std::string RuntimeOption::DebuggerStartupDocument;
473 int RuntimeOption::DebuggerSignalTimeout = 1;
475 std::string RuntimeOption::SendmailPath;
476 std::string RuntimeOption::MailForceExtraParameters;
478 long RuntimeOption::PregBacktraceLimit = 1000000;
479 long RuntimeOption::PregRecursionLimit = 100000;
480 bool RuntimeOption::EnablePregErrorLog = true;
482 bool RuntimeOption::HHProfServerEnabled = false;
483 int RuntimeOption::HHProfServerPort = 4327;
484 int RuntimeOption::HHProfServerThreads = 2;
485 int RuntimeOption::HHProfServerTimeoutSeconds = 30;
486 bool RuntimeOption::HHProfServerProfileClientMode = true;
487 bool RuntimeOption::HHProfServerAllocationProfile = false;
488 int RuntimeOption::HHProfServerFilterMinAllocPerReq = 2;
489 int RuntimeOption::HHProfServerFilterMinBytesPerReq = 128;
491 bool RuntimeOption::EnableHotProfiler = true;
492 int RuntimeOption::ProfilerTraceBuffer = 2000000;
493 double RuntimeOption::ProfilerTraceExpansion = 1.2;
494 int RuntimeOption::ProfilerMaxTraceBuffer = 0;
496 #ifdef FACEBOOK
497 bool RuntimeOption::EnableFb303Server = true;
498 int RuntimeOption::Fb303ServerPort;
499 int RuntimeOption::Fb303ServerThreadStackSizeMb = 8;
500 int RuntimeOption::Fb303ServerWorkerThreads = 1;
501 int RuntimeOption::Fb303ServerPoolThreads = 1;
502 #endif
504 int RuntimeOption::EnableAlternative = 0;
506 ///////////////////////////////////////////////////////////////////////////////
508 static void setResourceLimit(int resource, Hdf rlimit, const char *nodeName) {
509 if (!rlimit[nodeName].getString().empty()) {
510 struct rlimit rl;
511 getrlimit(resource, &rl);
512 rl.rlim_cur = rlimit[nodeName].getInt64();
513 if (rl.rlim_max < rl.rlim_cur) {
514 rl.rlim_max = rl.rlim_cur;
516 int ret = setrlimit(resource, &rl);
517 if (ret) {
518 Logger::Error("Unable to set %s to %" PRId64 ": %s (%d)",
519 nodeName, (int64_t)rl.rlim_cur,
520 folly::errnoStr(errno).c_str(), errno);
525 static void normalizePath(std::string &path) {
526 if (!path.empty()) {
527 if (path[path.length() - 1] == '/') {
528 path = path.substr(0, path.length() - 1);
530 if (path[0] != '/') {
531 path = std::string("/") + path;
536 static bool matchHdfPattern(const std::string &value, Hdf hdfPattern) {
537 string pattern = hdfPattern.getString();
538 if (!pattern.empty()) {
539 Variant ret = preg_match(String(pattern.c_str(), pattern.size(),
540 CopyString),
541 String(value.c_str(), value.size(),
542 CopyString));
543 if (ret.toInt64() <= 0) {
544 return false;
547 return true;
550 void RuntimeOption::Load(Hdf &config, StringVec *overwrites /* = NULL */,
551 bool empty /* = false */) {
552 // Machine metrics
553 string hostname, tier, cpu;
555 Hdf machine = config["Machine"];
557 hostname = machine["name"].getString();
558 if (hostname.empty()) {
559 hostname = Process::GetHostName();
562 tier = machine["tier"].getString();
564 cpu = machine["cpu"].getString();
565 if (cpu.empty()) {
566 cpu = Process::GetCPUModel();
570 if (overwrites) {
571 // Do these first, mainly so we can override Tier.*.machine,
572 // Tier.*.tier and Tier.*.cpu on the command line. But it can
573 // also make sense to override fields within a Tier (
574 // eg if you are using the same command line across a lot
575 // of different machines)
576 for (unsigned int i = 0; i < overwrites->size(); i++) {
577 config.fromString(overwrites->at(i).c_str());
581 // Tier overwrites
583 Hdf tiers = config["Tiers"];
584 for (Hdf hdf = tiers.firstChild(); hdf.exists(); hdf = hdf.next()) {
585 if (matchHdfPattern(hostname, hdf["machine"]) &&
586 matchHdfPattern(tier, hdf["tier"]) &&
587 matchHdfPattern(cpu, hdf["cpu"])) {
588 Tier = hdf.getName();
589 config.copy(hdf["overwrite"]);
590 // no break here, so we can continue to match more overwrites
592 hdf["overwrite"].setVisited(); // avoid lint complaining
596 if (overwrites) {
597 // Do the command line overrides again, so we override
598 // any tier overwrites
599 for (unsigned int i = 0; i < overwrites->size(); i++) {
600 config.fromString(overwrites->at(i).c_str());
604 PidFile = config["PidFile"].getString("www.pid");
606 config["DynamicInvokeFunctions"].get(DynamicInvokeFunctions);
609 Hdf logger = config["Log"];
610 if (logger["Level"] == "None") {
611 Logger::LogLevel = Logger::LogNone;
612 } else if (logger["Level"] == "Error") {
613 Logger::LogLevel = Logger::LogError;
614 } else if (logger["Level"] == "Warning") {
615 Logger::LogLevel = Logger::LogWarning;
616 } else if (logger["Level"] == "Info") {
617 Logger::LogLevel = Logger::LogInfo;
618 } else if (logger["Level"] == "Verbose") {
619 Logger::LogLevel = Logger::LogVerbose;
621 Logger::LogHeader = logger["Header"].getBool();
622 bool logInjectedStackTrace = logger["InjectedStackTrace"].getBool();
623 if (logInjectedStackTrace) {
624 Logger::SetTheLogger(new ExtendedLogger());
625 ExtendedLogger::EnabledByDefault = true;
627 Logger::LogNativeStackTrace = logger["NativeStackTrace"].getBool(true);
628 Logger::MaxMessagesPerRequest =
629 logger["MaxMessagesPerRequest"].getInt32(-1);
631 Logger::UseSyslog = logger["UseSyslog"].getBool(false);
632 Logger::UseLogFile = logger["UseLogFile"].getBool(true);
633 Logger::UseCronolog = logger["UseCronolog"].getBool(false);
634 if (Logger::UseLogFile) {
635 LogFile = logger["File"].getString();
636 if (LogFile[0] == '|') Logger::IsPipeOutput = true;
637 LogFileSymLink = logger["SymLink"].getString();
639 LogFileFlusher::DropCacheChunkSize =
640 logger["DropCacheChunkSize"].getInt32(1 << 20);
641 AlwaysEscapeLog = logger["AlwaysEscapeLog"].getBool(false);
642 RuntimeOption::LogHeaderMangle = logger["HeaderMangle"].getInt32(0);
644 AlwaysLogUnhandledExceptions =
645 logger["AlwaysLogUnhandledExceptions"].getBool(true);
646 NoSilencer = logger["NoSilencer"].getBool();
647 EnableApplicationLog = logger["ApplicationLog"].getBool(true);
648 RuntimeErrorReportingLevel =
649 logger["RuntimeErrorReportingLevel"]
650 .getInt32(static_cast<int>(ErrorConstants::ErrorModes::HPHP_ALL));
652 AccessLogDefaultFormat = logger["AccessLogDefaultFormat"].
653 getString("%h %l %u %t \"%r\" %>s %b");
655 Hdf access = logger["Access"];
656 for (Hdf hdf = access.firstChild(); hdf.exists();
657 hdf = hdf.next()) {
658 string fname = hdf["File"].getString();
659 if (fname.empty()) {
660 continue;
662 string symLink = hdf["SymLink"].getString();
663 AccessLogs.
664 push_back(AccessLogFileData(fname, symLink, hdf["Format"].
665 getString(AccessLogDefaultFormat)));
669 AdminLogFormat = logger["AdminLog.Format"].getString("%h %t %s %U");
670 AdminLogFile = logger["AdminLog.File"].getString();
671 AdminLogSymLink = logger["AdminLog.SymLink"].getString();
674 Hdf error = config["ErrorHandling"];
676 /* Remove this, once its removed from production configs */
677 (void)error["NoInfiniteLoopDetection"].getBool();
679 MaxSerializedStringSize =
680 error["MaxSerializedStringSize"].getInt32(64 * 1024 * 1024);
681 CallUserHandlerOnFatals = error["CallUserHandlerOnFatals"].getBool(true);
682 ThrowExceptionOnBadMethodCall =
683 error["ThrowExceptionOnBadMethodCall"].getBool(true);
684 MaxLoopCount = error["MaxLoopCount"].getInt32(0);
685 NoInfiniteRecursionDetection =
686 error["NoInfiniteRecursionDetection"].getBool();
687 ThrowBadTypeExceptions = error["ThrowBadTypeExceptions"].getBool();
688 ThrowTooManyArguments = error["ThrowTooManyArguments"].getBool();
689 WarnTooManyArguments = error["WarnTooManyArguments"].getBool();
690 ThrowMissingArguments = error["ThrowMissingArguments"].getBool();
691 ThrowInvalidArguments = error["ThrowInvalidArguments"].getBool();
692 EnableHipHopErrors = error["EnableHipHopErrors"].getBool(true);
693 AssertActive = error["AssertActive"].getBool();
694 AssertWarning = error["AssertWarning"].getBool();
695 NoticeFrequency = error["NoticeFrequency"].getInt32(1);
696 WarningFrequency = error["WarningFrequency"].getInt32(1);
699 Hdf rlimit = config["ResourceLimit"];
700 if (rlimit["CoreFileSizeOverride"].getInt64()) {
701 setResourceLimit(RLIMIT_CORE, rlimit, "CoreFileSizeOverride");
702 } else {
703 setResourceLimit(RLIMIT_CORE, rlimit, "CoreFileSize");
705 setResourceLimit(RLIMIT_NOFILE, rlimit, "MaxSocket");
706 setResourceLimit(RLIMIT_DATA, rlimit, "RSS");
707 MaxRSS = rlimit["MaxRSS"].getInt64(0);
708 SocketDefaultTimeout = rlimit["SocketDefaultTimeout"].getInt16(5);
709 MaxRSSPollingCycle = rlimit["MaxRSSPollingCycle"].getInt64(0);
710 DropCacheCycle = rlimit["DropCacheCycle"].getInt64(0);
711 MaxSQLRowCount = rlimit["MaxSQLRowCount"].getInt64(0);
712 MaxMemcacheKeyCount = rlimit["MaxMemcacheKeyCount"].getInt64(0);
713 SerializationSizeLimit =
714 rlimit["SerializationSizeLimit"].getInt64(StringData::MaxSize);
715 StringOffsetLimit = rlimit["StringOffsetLimit"].getInt64(10 * 1024 * 1024);
718 Hdf server = config["Server"];
719 Host = server["Host"].getString();
720 DefaultServerNameSuffix = server["DefaultServerNameSuffix"].getString();
721 ServerType = server["Type"].getString(ServerType);
722 ServerIP = server["IP"].getString();
723 ServerPrimaryIP = Util::GetPrimaryIP();
724 ServerPort = server["Port"].getUInt16(80);
725 ServerBacklog = server["Backlog"].getInt16(128);
726 ServerConnectionLimit = server["ConnectionLimit"].getInt16(0);
727 ServerThreadCount = server["ThreadCount"].getInt32(50);
728 ServerThreadRoundRobin = server["ThreadRoundRobin"].getBool();
729 ServerWarmupThrottleRequestCount =
730 server["WarmupThrottleRequestCount"].getInt32(
731 kDefaultWarmupThrottleRequestCount
733 ServerThreadDropCacheTimeoutSeconds =
734 server["ThreadDropCacheTimeoutSeconds"].getInt32(0);
735 if (server["ThreadJobLIFO"].getBool()) {
736 ServerThreadJobLIFOSwitchThreshold = 0;
738 ServerThreadJobLIFOSwitchThreshold =
739 server["ThreadJobLIFOSwitchThreshold"].getInt32(
740 ServerThreadJobLIFOSwitchThreshold);
741 ServerThreadJobMaxQueuingMilliSeconds =
742 server["ThreadJobMaxQueuingMilliSeconds"].getInt16(-1);
743 ServerThreadDropStack = server["ThreadDropStack"].getBool();
744 ServerHttpSafeMode = server["HttpSafeMode"].getBool();
745 ServerStatCache = server["StatCache"].getBool(true);
746 server["WarmupRequests"].get(ServerWarmupRequests);
747 server["HighPriorityEndPoints"].get(ServerHighPriorityEndPoints);
749 RequestTimeoutSeconds = server["RequestTimeoutSeconds"].getInt32(0);
750 PspTimeoutSeconds = server["PspTimeoutSeconds"].getInt32(0);
751 ServerMemoryHeadRoom = server["MemoryHeadRoom"].getInt64(0);
752 RequestMemoryMaxBytes = server["RequestMemoryMaxBytes"].
753 getInt64(std::numeric_limits<int64_t>::max());
754 ResponseQueueCount = server["ResponseQueueCount"].getInt32(0);
755 if (ResponseQueueCount <= 0) {
756 ResponseQueueCount = ServerThreadCount / 10;
757 if (ResponseQueueCount <= 0) ResponseQueueCount = 1;
759 ServerGracefulShutdownWait = server["GracefulShutdownWait"].getInt16(0);
760 ServerHarshShutdown = server["HarshShutdown"].getBool(true);
761 ServerEvilShutdown = server["EvilShutdown"].getBool(true);
762 ServerDanglingWait = server["DanglingWait"].getInt16(0);
763 ServerShutdownListenWait = server["ShutdownListenWait"].getInt16(0);
764 ServerShutdownListenNoWork = server["ShutdownListenNoWork"].getInt16(-1);
765 if (ServerGracefulShutdownWait < ServerDanglingWait) {
766 ServerGracefulShutdownWait = ServerDanglingWait;
768 GzipCompressionLevel = server["GzipCompressionLevel"].getInt16(3);
770 ForceCompressionURL = server["ForceCompression"]["URL"].getString();
771 ForceCompressionCookie = server["ForceCompression"]["Cookie"].getString();
772 ForceCompressionParam = server["ForceCompression"]["Param"].getString();
774 EnableMagicQuotesGpc = server["EnableMagicQuotesGpc"].getBool();
775 EnableKeepAlive = server["EnableKeepAlive"].getBool(true);
776 ExposeHPHP = server["ExposeHPHP"].getBool(true);
777 ExposeXFBServer = server["ExposeXFBServer"].getBool(false);
778 ExposeXFBDebug = server["ExposeXFBDebug"].getBool(false);
779 XFBDebugSSLKey = server["XFBDebugSSLKey"].getString("");
780 ConnectionTimeoutSeconds = server["ConnectionTimeoutSeconds"].getInt16(-1);
781 EnableOutputBuffering = server["EnableOutputBuffering"].getBool();
782 OutputHandler = server["OutputHandler"].getString();
783 ImplicitFlush = server["ImplicitFlush"].getBool();
784 EnableEarlyFlush = server["EnableEarlyFlush"].getBool(true);
785 ForceChunkedEncoding = server["ForceChunkedEncoding"].getBool();
786 MaxPostSize = (server["MaxPostSize"].getInt32(100)) * (1LL << 20);
787 AlwaysPopulateRawPostData =
788 server["AlwaysPopulateRawPostData"].getBool(true);
789 LibEventSyncSend = server["LibEventSyncSend"].getBool(true);
790 TakeoverFilename = server["TakeoverFilename"].getString();
791 ExpiresActive = server["ExpiresActive"].getBool(true);
792 ExpiresDefault = server["ExpiresDefault"].getInt32(2592000);
793 if (ExpiresDefault < 0) ExpiresDefault = 2592000;
794 DefaultCharsetName = server["DefaultCharsetName"].getString("utf-8");
796 RequestBodyReadLimit = server["RequestBodyReadLimit"].getInt32(-1);
798 EnableSSL = server["EnableSSL"].getBool();
799 SSLPort = server["SSLPort"].getUInt16(443);
800 SSLCertificateFile = server["SSLCertificateFile"].getString();
801 SSLCertificateKeyFile = server["SSLCertificateKeyFile"].getString();
802 SSLCertificateDir = server["SSLCertificateDir"].getString();
803 TLSDisableTLS1_2 = server["TLSDisableTLS1_2"].getBool(false);
804 TLSClientCipherSpec = server["TLSClientCipherSpec"].getString();
806 string srcRoot = Util::normalizeDir(server["SourceRoot"].getString());
807 if (!srcRoot.empty()) SourceRoot = srcRoot;
808 FileCache::SourceRoot = SourceRoot;
810 server["IncludeSearchPaths"].get(IncludeSearchPaths);
811 for (unsigned int i = 0; i < IncludeSearchPaths.size(); i++) {
812 IncludeSearchPaths[i] = Util::normalizeDir(IncludeSearchPaths[i]);
814 IncludeSearchPaths.insert(IncludeSearchPaths.begin(), ".");
816 FileCache = server["FileCache"].getString();
817 DefaultDocument = server["DefaultDocument"].getString();
818 ErrorDocument404 = server["ErrorDocument404"].getString();
819 normalizePath(ErrorDocument404);
820 ForbiddenAs404 = server["ForbiddenAs404"].getBool();
821 ErrorDocument500 = server["ErrorDocument500"].getString();
822 normalizePath(ErrorDocument500);
823 FatalErrorMessage = server["FatalErrorMessage"].getString();
824 FontPath = Util::normalizeDir(server["FontPath"].getString());
825 EnableStaticContentCache =
826 server["EnableStaticContentCache"].getBool(true);
827 EnableStaticContentFromDisk =
828 server["EnableStaticContentFromDisk"].getBool(true);
829 EnableOnDemandUncompress =
830 server["EnableOnDemandUncompress"].getBool(true);
831 EnableStaticContentMMap =
832 server["EnableStaticContentMMap"].getBool(true);
833 if (EnableStaticContentMMap) {
834 EnableOnDemandUncompress = true;
836 Utf8izeReplace = server["Utf8izeReplace"].getBool(true);
838 StartupDocument = server["StartupDocument"].getString();
839 normalizePath(StartupDocument);
840 WarmupDocument = server["WarmupDocument"].getString();
841 RequestInitFunction = server["RequestInitFunction"].getString();
842 RequestInitDocument = server["RequestInitDocument"].getString();
843 server["ThreadDocuments"].get(ThreadDocuments);
844 for (unsigned int i = 0; i < ThreadDocuments.size(); i++) {
845 normalizePath(ThreadDocuments[i]);
847 server["ThreadLoopDocuments"].get(ThreadLoopDocuments);
848 for (unsigned int i = 0; i < ThreadLoopDocuments.size(); i++) {
849 normalizePath(ThreadLoopDocuments[i]);
852 SafeFileAccess = server["SafeFileAccess"].getBool();
853 server["AllowedDirectories"].get(AllowedDirectories);
855 WhitelistExec = server["WhitelistExec"].getBool();
856 WhitelistExecWarningOnly = server["WhitelistExecWarningOnly"].getBool();
857 server["AllowedExecCmds"].get(AllowedExecCmds);
859 UnserializationWhitelistCheck =
860 server["UnserializationWhitelistCheck"].getBool(false);
861 UnserializationWhitelistCheckWarningOnly =
862 server["UnserializationWhitelistCheckWarningOnly"].getBool(true);
864 server["AllowedFiles"].get(AllowedFiles);
866 server["ForbiddenFileExtensions"].get(ForbiddenFileExtensions);
868 LockCodeMemory = server["LockCodeMemory"].getBool(false);
869 MaxArrayChain = server["MaxArrayChain"].getInt32(INT_MAX);
870 if (MaxArrayChain != INT_MAX) {
871 // HphpArray needs a higher threshold to avoid false-positives.
872 // (and we always use HphpArray)
873 MaxArrayChain *= 2;
876 WarnOnCollectionToArray = server["WarnOnCollectionToArray"].getBool(false);
877 UseDirectCopy = server["UseDirectCopy"].getBool(false);
878 AlwaysUseRelativePath = server["AlwaysUseRelativePath"].getBool(false);
880 IniFile = server["IniFile"].getString(IniFile);
881 if (access(IniFile.c_str(), R_OK) == -1) {
882 if (IniFile != "/etc/hhvm/php.ini") {
883 Logger::Error("INI file doens't exist: %s", IniFile.c_str());
885 IniFile.clear();
888 Hdf dns = server["DnsCache"];
889 EnableDnsCache = dns["Enable"].getBool();
890 DnsCacheTTL = dns["TTL"].getInt32(600); // 10 minutes
891 DnsCacheKeyMaturityThreshold = dns["KeyMaturityThreshold"].getInt32(20);
892 DnsCacheMaximumCapacity = dns["MaximumCapacity"].getInt64(0);
893 DnsCacheKeyFrequencyUpdatePeriod = dns["KeyFrequencyUpdatePeriod"].
894 getInt32(1000);
896 Hdf upload = server["Upload"];
897 UploadMaxFileSize =
898 (upload["UploadMaxFileSize"].getInt32(100)) * (1LL << 20);
899 UploadTmpDir = upload["UploadTmpDir"].getString("/tmp");
900 RuntimeOption::AllowedDirectories.push_back(UploadTmpDir);
901 EnableFileUploads = upload["EnableFileUploads"].getBool(true);
902 EnableUploadProgress = upload["EnableUploadProgress"].getBool();
903 Rfc1867Freq = upload["Rfc1867Freq"].getInt32(256 * 1024);
904 if (Rfc1867Freq < 0) Rfc1867Freq = 256 * 1024;
905 Rfc1867Prefix = upload["Rfc1867Prefix"].getString("vupload_");
906 Rfc1867Name = upload["Rfc1867Name"].getString("video_ptoken");
908 ImageMemoryMaxBytes = server["ImageMemoryMaxBytes"].getInt64(0);
909 if (ImageMemoryMaxBytes == 0) {
910 ImageMemoryMaxBytes = UploadMaxFileSize * 2;
912 SharedStores::Create();
914 LightProcessFilePrefix =
915 server["LightProcessFilePrefix"].getString("./lightprocess");
916 LightProcessCount = server["LightProcessCount"].getInt32(0);
918 InjectedStackTrace = server["InjectedStackTrace"].getBool(true);
919 InjectedStackTraceLimit = server["InjectedStackTraceLimit"].getInt32(-1);
921 ForceServerNameToHeader = server["ForceServerNameToHeader"].getBool();
923 EnableCufAsync = server["EnableCufAsync"].getBool(false);
925 ServerUser = server["User"].getString("");
928 VirtualHost::SortAllowedDirectories(AllowedDirectories);
930 Hdf hosts = config["VirtualHost"];
931 if (hosts.exists()) {
932 for (Hdf hdf = hosts.firstChild(); hdf.exists(); hdf = hdf.next()) {
933 if (hdf.getName() == "default") {
934 VirtualHost::GetDefault().init(hdf);
935 VirtualHost::GetDefault().addAllowedDirectories(AllowedDirectories);
936 } else {
937 VirtualHostPtr host(new VirtualHost(hdf));
938 host->addAllowedDirectories(AllowedDirectories);
939 VirtualHosts.push_back(host);
942 for (unsigned int i = 0; i < VirtualHosts.size(); i++) {
943 if (!VirtualHosts[i]->valid()) {
944 throw InvalidArgumentException("virtual host",
945 "missing prefix or pattern");
951 Hdf ipblocks = config["IpBlockMap"];
952 IpBlocks = IpBlockMapPtr(new IpBlockMap(ipblocks));
955 Hdf satellites = config["Satellites"];
956 if (satellites.exists()) {
957 for (Hdf hdf = satellites.firstChild(); hdf.exists(); hdf = hdf.next()) {
958 SatelliteServerInfoPtr satellite(new SatelliteServerInfo(hdf));
959 SatelliteServerInfos.push_back(satellite);
960 if (satellite->getType() == SatelliteServer::Type::KindOfRPCServer) {
961 XboxPassword = satellite->getPassword();
962 XboxPasswords = satellite->getPasswords();
968 Hdf xbox = config["Xbox"];
969 XboxServerThreadCount = xbox["ServerInfo.ThreadCount"].getInt32(10);
970 XboxServerMaxQueueLength =
971 xbox["ServerInfo.MaxQueueLength"].getInt32(INT_MAX);
972 if (XboxServerMaxQueueLength < 0) XboxServerMaxQueueLength = INT_MAX;
973 XboxServerPort = xbox["ServerInfo.Port"].getInt32(0);
974 XboxDefaultLocalTimeoutMilliSeconds =
975 xbox["DefaultLocalTimeoutMilliSeconds"].getInt32(500);
976 XboxDefaultRemoteTimeoutSeconds =
977 xbox["DefaultRemoteTimeoutSeconds"].getInt32(5);
978 XboxServerInfoMaxRequest = xbox["ServerInfo.MaxRequest"].getInt32(500);
979 XboxServerInfoDuration = xbox["ServerInfo.MaxDuration"].getInt32(120);
980 XboxServerInfoWarmupDoc = xbox["ServerInfo.WarmupDocument"].get("");
981 XboxServerInfoReqInitFunc = xbox["ServerInfo.RequestInitFunction"].get("");
982 XboxServerInfoReqInitDoc = xbox["ServerInfo.RequestInitDocument"].get("");
983 XboxServerInfoAlwaysReset = xbox["ServerInfo.AlwaysReset"].getBool(false);
984 XboxServerLogInfo = xbox["ServerInfo.LogInfo"].getBool(false);
985 XboxProcessMessageFunc =
986 xbox["ProcessMessageFunc"].get("xbox_process_message");
989 Hdf pagelet = config["PageletServer"];
990 PageletServerThreadCount = pagelet["ThreadCount"].getInt32(0);
991 PageletServerThreadRoundRobin = pagelet["ThreadRoundRobin"].getBool();
992 PageletServerThreadDropStack = pagelet["ThreadDropStack"].getBool();
993 PageletServerThreadDropCacheTimeoutSeconds =
994 pagelet["ThreadDropCacheTimeoutSeconds"].getInt32(0);
995 PageletServerQueueLimit = pagelet["QueueLimit"].getInt32(0);
998 FiberCount = config["Fiber.ThreadCount"].getInt32(Process::GetCPUCount());
1001 Hdf content = config["StaticFile"];
1002 content["Extensions"].get(StaticFileExtensions);
1003 content["Generators"].get(StaticFileGenerators);
1005 Hdf matches = content["FilesMatch"];
1006 if (matches.exists()) {
1007 for (Hdf hdf = matches.firstChild(); hdf.exists(); hdf = hdf.next()) {
1008 FilesMatches.push_back(FilesMatchPtr(new FilesMatch(hdf)));
1013 Hdf phpfile = config["PhpFile"];
1014 phpfile["Extensions"].get(PhpFileExtensions);
1017 Hdf admin = config["AdminServer"];
1018 AdminServerPort = admin["Port"].getInt16(0);
1019 AdminThreadCount = admin["ThreadCount"].getInt32(1);
1020 AdminPassword = admin["Password"].getString();
1021 admin["Passwords"].get(AdminPasswords);
1024 Hdf proxy = config["Proxy"];
1025 ProxyOrigin = proxy["Origin"].getString();
1026 ProxyRetry = proxy["Retry"].getInt16(3);
1027 UseServeURLs = proxy["ServeURLs"].getBool();
1028 proxy["ServeURLs"].get(ServeURLs);
1029 UseProxyURLs = proxy["ProxyURLs"].getBool();
1030 ProxyPercentage = proxy["Percentage"].getByte(0);
1031 proxy["ProxyURLs"].get(ProxyURLs);
1032 proxy["ProxyPatterns"].get(ProxyPatterns);
1035 Hdf http = config["Http"];
1036 HttpDefaultTimeout = http["DefaultTimeout"].getInt32(30);
1037 HttpSlowQueryThreshold = http["SlowQueryThreshold"].getInt32(5000);
1040 Hdf debug = config["Debug"];
1041 NativeStackTrace = debug["NativeStackTrace"].getBool();
1042 StackTrace::Enabled = NativeStackTrace;
1043 TranslateLeakStackTrace = debug["TranslateLeakStackTrace"].getBool();
1044 FullBacktrace = debug["FullBacktrace"].getBool();
1045 ServerStackTrace = debug["ServerStackTrace"].getBool();
1046 ServerErrorMessage = debug["ServerErrorMessage"].getBool();
1047 TranslateSource = debug["TranslateSource"].getBool();
1048 RecordInput = debug["RecordInput"].getBool();
1049 ClearInputOnSuccess = debug["ClearInputOnSuccess"].getBool(true);
1050 ProfilerOutputDir = debug["ProfilerOutputDir"].getString("/tmp");
1051 CoreDumpEmail = debug["CoreDumpEmail"].getString();
1052 CoreDumpReport = debug["CoreDumpReport"].getBool(true);
1053 if (CoreDumpReport) {
1054 install_crash_reporter();
1056 CoreDumpReportDirectory =
1057 debug["CoreDumpReportDirectory"].getString(CoreDumpReportDirectory);
1058 LocalMemcache = debug["LocalMemcache"].getBool();
1059 MemcacheReadOnly = debug["MemcacheReadOnly"].getBool();
1062 Hdf simpleCounter = debug["SimpleCounter"];
1063 SimpleCounter::SampleStackCount =
1064 simpleCounter["SampleStackCount"].getInt32(0);
1065 SimpleCounter::SampleStackDepth =
1066 simpleCounter["SampleStackDepth"].getInt32(5);
1070 Hdf stats = config["Stats"];
1071 EnableStats = stats.getBool(); // main switch
1073 EnableWebStats = stats["Web"].getBool();
1074 EnableMemoryStats = stats["Memory"].getBool();
1075 EnableAPCStats = stats["APC"].getBool();
1076 EnableAPCKeyStats = stats["APCKey"].getBool();
1077 EnableMemcacheStats = stats["Memcache"].getBool();
1078 EnableMemcacheKeyStats = stats["MemcacheKey"].getBool();
1079 EnableSQLStats = stats["SQL"].getBool();
1080 EnableSQLTableStats = stats["SQLTable"].getBool();
1081 EnableNetworkIOStatus = stats["NetworkIO"].getBool();
1083 StatsXSL = stats["XSL"].getString();
1084 StatsXSLProxy = stats["XSLProxy"].getString();
1086 StatsSlotDuration = stats["SlotDuration"].getInt32(10 * 60); // 10 minutes
1087 StatsMaxSlot = stats["MaxSlot"].getInt32(12 * 6); // 12 hours
1090 Hdf apcSize = stats["APCSize"];
1091 EnableAPCSizeStats = apcSize["Enable"].getBool();
1092 EnableAPCSizeGroup = apcSize["Group"].getBool();
1093 apcSize["SpecialPrefix"].get(APCSizeSpecialPrefix);
1094 for (unsigned int i = 0; i < APCSizeSpecialPrefix.size(); i++) {
1095 string &prefix = APCSizeSpecialPrefix[i];
1096 string prefixReplace = prefix + "{A}";
1097 APCSizePrefixReplace.push_back(prefixReplace);
1099 apcSize["SpecialMiddle"].get(APCSizeSpecialMiddle);
1100 for (unsigned int i = 0; i < APCSizeSpecialMiddle.size(); i++) {
1101 string &middle = APCSizeSpecialMiddle[i];
1102 string middleReplace = "{A}" + middle + "{A}";
1103 APCSizeMiddleReplace.push_back(middleReplace);
1105 apcSize["SkipPrefix"].get(APCSizeSkipPrefix);
1106 EnableAPCSizeDetail = apcSize["Individual"].getBool();
1107 EnableAPCFetchStats = apcSize["FetchStats"].getBool();
1108 if (EnableAPCFetchStats) EnableAPCSizeDetail = true;
1109 if (EnableAPCSizeDetail) EnableAPCSizeGroup = true;
1110 APCSizeCountPrime = apcSize["CountPrime"].getBool();
1113 EnableHotProfiler = stats["EnableHotProfiler"].getBool(true);
1114 ProfilerTraceBuffer = stats["ProfilerTraceBuffer"].getInt32(2000000);
1115 ProfilerTraceExpansion = stats["ProfilerTraceExpansion"].getDouble(1.2);
1116 ProfilerMaxTraceBuffer = stats["ProfilerMaxTraceBuffer"].getInt32(0);
1119 config["ServerVariables"].get(ServerVariables);
1120 config["EnvVariables"].get(EnvVariables);
1123 Hdf eval = config["Eval"];
1124 EnableHipHopSyntax = eval["EnableHipHopSyntax"].getBool();
1125 EnableHipHopExperimentalSyntax =
1126 eval["EnableHipHopExperimentalSyntax"].getBool();
1127 EnableShortTags= eval["EnableShortTags"].getBool(true);
1128 EnableAspTags = eval["EnableAspTags"].getBool();
1129 EnableXHP = eval["EnableXHP"].getBool(false);
1130 EnableZendCompat = eval["EnableZendCompat"].getBool(false);
1131 TimeoutsUseWallTime = eval["TimeoutsUseWallTime"].getBool(true);
1133 if (EnableHipHopSyntax) {
1134 // If EnableHipHopSyntax is true, it forces EnableXHP to true
1135 // regardless of how it was set in the config
1136 EnableXHP = true;
1139 EnableObjDestructCall = eval["EnableObjDestructCall"].getBool(false);
1140 MaxUserFunctionId = eval["MaxUserFunctionId"].getInt32(2 * 65536);
1141 CheckSymLink = eval["CheckSymLink"].getBool(true);
1143 EnableAlternative = eval["EnableAlternative"].getInt32(0);
1145 #define get_double getDouble
1146 #define get_bool getBool
1147 #define get_string getString
1148 #define get_int16 getInt16
1149 #define get_int32 getInt32
1150 #define get_int32_t getInt32
1151 #define get_int64 getInt64
1152 #define get_uint16 getUInt16
1153 #define get_uint32 getUInt32
1154 #define get_uint32_t getUInt32
1155 #define get_uint64 getUInt64
1156 #define get_uint64_t getUInt64
1157 #define F(type, name, defaultVal) \
1158 Eval ## name = eval[#name].get_ ##type(defaultVal);
1159 EVALFLAGS()
1160 #undef F
1161 #undef get_double
1162 #undef get_bool
1163 #undef get_string
1164 #undef get_int16
1165 #undef get_int32
1166 #undef get_int64
1167 #undef get_uint16
1168 #undef get_uint32
1169 #undef get_uint32_t
1170 #undef get_uint64
1171 Util::low_malloc_huge_pages(EvalMaxLowMemHugePages);
1172 EvalJitEnableRenameFunction = EvalJitEnableRenameFunction || !EvalJit;
1174 EnableEmitSwitch = eval["EnableEmitSwitch"].getBool(true);
1175 EnableEmitterStats = eval["EnableEmitterStats"].getBool(EnableEmitterStats);
1176 EnableInstructionCounts = eval["EnableInstructionCounts"].getBool(false);
1177 RecordCodeCoverage = eval["RecordCodeCoverage"].getBool();
1178 if (EvalJit && RecordCodeCoverage) {
1179 throw InvalidArgumentException(
1180 "code coverage", "Code coverage is not supported for Eval.Jit=true");
1182 if (RecordCodeCoverage) CheckSymLink = true;
1183 CodeCoverageOutputFile = eval["CodeCoverageOutputFile"].getString();
1185 Hdf debugger = eval["Debugger"];
1186 EnableDebugger = debugger["EnableDebugger"].getBool();
1187 EnableDebuggerColor = debugger["EnableDebuggerColor"].getBool(true);
1188 EnableDebuggerPrompt = debugger["EnableDebuggerPrompt"].getBool(true);
1189 EnableDebuggerServer = debugger["EnableDebuggerServer"].getBool();
1190 EnableDebuggerUsageLog = debugger["EnableDebuggerUsageLog"].getBool();
1191 DebuggerServerPort = debugger["Port"].getUInt16(8089);
1192 DebuggerDisableIPv6 = debugger["DisableIPv6"].getBool(false);
1193 DebuggerDefaultSandboxPath = debugger["DefaultSandboxPath"].getString();
1194 DebuggerStartupDocument = debugger["StartupDocument"].getString();
1195 DebuggerSignalTimeout = debugger["SignalTimeout"].getInt32(1);
1197 DebuggerDefaultRpcPort = debugger["RPC.DefaultPort"].getUInt16(8083);
1198 DebuggerDefaultRpcAuth = debugger["RPC.DefaultAuth"].getString();
1199 DebuggerRpcHostDomain = debugger["RPC.HostDomain"].getString();
1200 DebuggerDefaultRpcTimeout = debugger["RPC.DefaultTimeout"].getInt32(30);
1203 Hdf repo = config["Repo"];
1205 Hdf repoLocal = repo["Local"];
1206 // Repo.Local.Mode.
1207 RepoLocalMode = repoLocal["Mode"].getString();
1208 if (!empty && RepoLocalMode.empty()) {
1209 const char* HHVM_REPO_LOCAL_MODE = getenv("HHVM_REPO_LOCAL_MODE");
1210 if (HHVM_REPO_LOCAL_MODE != nullptr) {
1211 RepoLocalMode = HHVM_REPO_LOCAL_MODE;
1214 if (RepoLocalMode.empty()) {
1215 RepoLocalMode = "r-";
1217 if (RepoLocalMode.compare("rw")
1218 && RepoLocalMode.compare("r-")
1219 && RepoLocalMode.compare("--")) {
1220 Logger::Error("Bad config setting: Repo.Local.Mode=%s",
1221 RepoLocalMode.c_str());
1222 RepoLocalMode = "rw";
1224 // Repo.Local.Path.
1225 RepoLocalPath = repoLocal["Path"].getString();
1226 if (!empty && RepoLocalPath.empty()) {
1227 const char* HHVM_REPO_LOCAL_PATH = getenv("HHVM_REPO_LOCAL_PATH");
1228 if (HHVM_REPO_LOCAL_PATH != nullptr) {
1229 RepoLocalPath = HHVM_REPO_LOCAL_PATH;
1234 Hdf repoCentral = repo["Central"];
1235 // Repo.Central.Path.
1236 RepoCentralPath = repoCentral["Path"].getString();
1239 Hdf repoEval = repo["Eval"];
1240 // Repo.Eval.Mode.
1241 RepoEvalMode = repoEval["Mode"].getString();
1242 if (RepoEvalMode.empty()) {
1243 RepoEvalMode = "readonly";
1244 } else if (RepoEvalMode.compare("local")
1245 && RepoEvalMode.compare("central")
1246 && RepoEvalMode.compare("readonly")) {
1247 Logger::Error("Bad config setting: Repo.Eval.Mode=%s",
1248 RepoEvalMode.c_str());
1249 RepoEvalMode = "readonly";
1252 RepoJournal = repo["Journal"].getString("delete");
1253 RepoCommit = repo["Commit"].getBool(true);
1254 RepoDebugInfo = repo["DebugInfo"].getBool(true);
1255 RepoAuthoritative = repo["Authoritative"].getBool(false);
1258 // NB: after we know the value of RepoAuthoritative.
1259 EnableArgsInBacktraces =
1260 eval["EnableArgsInBacktraces"].getBool(!RepoAuthoritative);
1263 Hdf sandbox = config["Sandbox"];
1264 SandboxMode = sandbox["SandboxMode"].getBool();
1265 SandboxPattern = Util::format_pattern
1266 (sandbox["Pattern"].getString(), true);
1267 SandboxHome = sandbox["Home"].getString();
1268 SandboxFallback = sandbox["Fallback"].getString();
1269 SandboxConfFile = sandbox["ConfFile"].getString();
1270 SandboxFromCommonRoot = sandbox["FromCommonRoot"].getBool();
1271 SandboxDirectoriesRoot = sandbox["DirectoriesRoot"].getString();
1272 SandboxLogsRoot = sandbox["LogsRoot"].getString();
1273 sandbox["ServerVariables"].get(SandboxServerVariables);
1276 Hdf mail = config["Mail"];
1277 SendmailPath = mail["SendmailPath"].getString("sendmail -t -i");
1278 MailForceExtraParameters = mail["ForceExtraParameters"].getString();
1281 Hdf preg = config["Preg"];
1282 PregBacktraceLimit = preg["BacktraceLimit"].getInt64(1000000);
1283 PregRecursionLimit = preg["RecursionLimit"].getInt64(100000);
1284 EnablePregErrorLog = preg["ErrorLog"].getBool(true);
1287 Hdf hhprofServer = config["HHProfServer"];
1288 HHProfServerEnabled = hhprofServer["Enabled"].getBool(false);
1289 HHProfServerPort = hhprofServer["Port"].getInt16(4327);
1290 HHProfServerThreads = hhprofServer["Threads"].getInt16(2);
1291 HHProfServerTimeoutSeconds =
1292 hhprofServer["TimeoutSeconds"].getInt64(30);
1293 HHProfServerProfileClientMode =
1294 hhprofServer["ProfileClientMode"].getBool(true);
1295 HHProfServerAllocationProfile =
1296 hhprofServer["AllocationProfile"].getBool(false);
1298 // HHProfServer.Filter.*
1299 Hdf hhprofFilter = hhprofServer["Filter"];
1300 HHProfServerFilterMinAllocPerReq =
1301 hhprofFilter["MinAllocPerReq"].getInt64(2);
1302 HHProfServerFilterMinBytesPerReq =
1303 hhprofFilter["MinBytesPerReq"].getInt64(128);
1305 #ifdef FACEBOOK
1307 Hdf fb303Server = config["Fb303Server"];
1308 EnableFb303Server = fb303Server["Enable"].getBool(true);
1309 Fb303ServerPort = fb303Server["Port"].getInt16(0);
1310 Fb303ServerThreadStackSizeMb = fb303Server["ThreadStackSizeMb"].getInt16(8);
1311 Fb303ServerWorkerThreads = fb303Server["WorkerThreads"].getInt16(1);
1312 Fb303ServerPoolThreads = fb303Server["PoolThreads"].getInt16(1);
1314 #endif
1316 Extension::LoadModules(config);
1317 if (overwrites) Loaded = true;
1320 ///////////////////////////////////////////////////////////////////////////////