Skip to content

Commit 9a9b42e

Browse files
scannellsgolemon
authored andcommitted
Use CPU time instead of wall time for time limit
Zend PHP does not count in sleeping time into scripts time limit, HHVM does. Change that for parity reasons. Closes #1279 Closes #1287 Reviewed By: @markw65 Differential Revision: D1066797
1 parent 0b04c8f commit 9a9b42e

File tree

4 files changed

+14
-1
lines changed

4 files changed

+14
-1
lines changed

hphp/doc/options.compiled

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,8 @@ users can use the same machine serving their own source files.
729729
}
730730
}
731731

732+
TimeoutsUseWallTime = true
733+
732734
# experimental, please ignore
733735
BytecodeInterpreter = false
734736
DumpBytecode = false
@@ -744,6 +746,11 @@ includes/requires and loading code. This is enabled by default for parity with
744746
the reference implementation. If not needed for a particular application and/or
745747
configuration, disable this when tuning.
746748

749+
- TimeoutsUseWallTime
750+
751+
Determines whether or not to interpret set_time_limit timeouts as wall time or
752+
CPU time (which the reference implementation uses.) Defaults to wall time.
753+
747754
= MySQL
748755

749756
MySQL {

hphp/runtime/base/runtime-option.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ int RuntimeOption::MaxUserFunctionId = (2 * 65536);
343343
bool RuntimeOption::EnableFinallyStatement = false;
344344
bool RuntimeOption::EnableArgsInBacktraces = true;
345345
bool RuntimeOption::EnableZendCompat = false;
346+
bool RuntimeOption::TimeoutsUseWallTime = true;
346347

347348
int RuntimeOption::GetScannerType() {
348349
int type = 0;
@@ -1105,6 +1106,7 @@ void RuntimeOption::Load(Hdf &config, StringVec *overwrites /* = NULL */,
11051106
EnableAspTags = eval["EnableAspTags"].getBool();
11061107
EnableXHP = eval["EnableXHP"].getBool(false);
11071108
EnableZendCompat = eval["EnableZendCompat"].getBool(false);
1109+
TimeoutsUseWallTime = eval["TimeoutsUseWallTime"].getBool(true);
11081110

11091111
if (EnableHipHopSyntax) {
11101112
// If EnableHipHopSyntax is true, it forces EnableXHP to true

hphp/runtime/base/runtime-option.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ class RuntimeOption {
337337
static bool EnableFinallyStatement;
338338
static bool EnableArgsInBacktraces;
339339
static bool EnableZendCompat;
340+
static bool TimeoutsUseWallTime;
340341

341342
static int GetScannerType();
342343

hphp/runtime/base/thread-info.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,10 @@ void RequestInjectionData::setTimeout(int seconds) {
145145
sev.sigev_notify = SIGEV_SIGNAL;
146146
sev.sigev_signo = SIGVTALRM;
147147
sev.sigev_value.sival_ptr = this;
148-
if (timer_create(CLOCK_REALTIME, &sev, &m_timer_id)) {
148+
auto const& clockType =
149+
RuntimeOption::TimeoutsUseWallTime ? CLOCK_REALTIME :
150+
CLOCK_THREAD_CPUTIME_ID;
151+
if (timer_create(clockType, &sev, &m_timer_id)) {
149152
raise_error("Failed to set timeout: %s", folly::errnoStr(errno).c_str());
150153
}
151154
m_hasTimer = true;

0 commit comments

Comments
 (0)