RequestTimeout
Request timeout library for Excimer with plain PHP fallback
Loading...
Searching...
No Matches
Wikimedia\RequestTimeout\CriticalSectionProvider Class Reference

A class providing a named critical section concept. More...

Public Member Functions

 __construct (RequestTimeout $requestTimeout, $emergencyLimit, $emergencyCallback, $implicitExitCallback)
 
 enter ( $name, $emergencyLimit=null, $emergencyCallback=null)
 Enter a critical section, giving it a name.
 
 exit ( $name)
 Exit a named critical section.
 
 scopedEnter ( $name, $emergencyLimit=null, $emergencyCallback=null, $implicitExitCallback=null)
 Enter a critical section, and return a scope variable.
 
 getEmergencyLimit ()
 Get the configured emergency time limit.
 

Detailed Description

A class providing a named critical section concept.

When the code is inside a critical section, if a request timeout occurs, it is queued and then delivered when the critical section exits.

The class stores configuration for "emergency timeouts". This is a second timeout which limits the amount of time a critical section may be open.

Member Function Documentation

◆ enter()

Wikimedia\RequestTimeout\CriticalSectionProvider::enter ( $name,
$emergencyLimit = null,
$emergencyCallback = null )

Enter a critical section, giving it a name.

The name should uniquely identify the calling code.

Multiple critical sections may be active at a given time. Critical sections created by this method must be exited in the reverse order to which they were created, i.e. there is a stack of named critical sections.

Parameters
string$name
float | null$emergencyLimitIf non-null, this will override the configured emergency timeout
callable | null$emergencyCallbackIf non-null, this will override the configured emergency timeout callback.

◆ exit()

Wikimedia\RequestTimeout\CriticalSectionProvider::exit ( $name)

Exit a named critical section.

If the name does not match the most recent call to enter(), an exception will be thrown.

Exceptions
CriticalSectionMismatchException
TimeoutException
Parameters
string$name

◆ getEmergencyLimit()

Wikimedia\RequestTimeout\CriticalSectionProvider::getEmergencyLimit ( )

Get the configured emergency time limit.

Since
1.1.0
Returns
float

◆ scopedEnter()

Wikimedia\RequestTimeout\CriticalSectionProvider::scopedEnter ( $name,
$emergencyLimit = null,
$emergencyCallback = null,
$implicitExitCallback = null )

Enter a critical section, and return a scope variable.

The critical section will automatically exit when the scope variable is destroyed.

Multiple critical sections may be active at a given time. There is no restriction on the order in which critical sections created by this method are exited.

NOTE: Callers should typically call CriticalSectionScope::exit() instead of waiting for __destruct() to be called, since exiting a critical section may throw a timeout exception, but it is a fatal error to throw an exception from a destructor during request shutdown.

Parameters
string$nameA name for the critical section, used in error messages
float | null$emergencyLimitIf non-null, this will override the configured emergency timeout
callable | null$emergencyCallbackIf non-null, this will override the configured emergency timeout callback.
callable | null$implicitExitCallbackIf non-null, this will override the configured implicit exit callback. The callback will be called if the section is exited in __destruct() instead of by calling exit().
Returns
CriticalSectionScope

The documentation for this class was generated from the following file: