This is automatic generated document for things in Swow\Thread class
Class Thread
An OS thread with its own PHP request.
The thread body and its arguments are serialized at start. The child request has no user code, no autoloader and no global state. A closure cannot be serialized, so a closure body cannot start. Use an internal function or a method of a Swow object that shares state by id.
Methods
Static method getCurrent
Return the Thread object for the current thread.
Throws ThreadException when Swow has no current thread.
Static method getCurrentId
Return the native id of the current thread.
This method returns 0 when Swow has no current thread.
Static method killAll
Send a kill request to every child thread.
This method does not wait for the threads to exit.
Returns int the number of threads that accepted the request
Static method run
Create and start a thread.
The body and the arguments are serialized. See the class description. This method waits for the child runtime. In a coroutine, this method suspends the current coroutine.
Param callable $callable The thread body. Param mixed $args Arguments for the thread body.
Throws ThreadException when the thread cannot start. Throws \Exception when the body or an argument cannot be serialized.
Static method runCode
Create and start a thread that runs PHP code.
The code runs as top level code in a fresh request. Parent globals are not visible. The code has no $context variable. The return value and the exceptions of the code are discarded. Read getExitStatus() for the result. This method waits for the child runtime. In a coroutine, this method suspends the current coroutine.
Param string $code PHP code without an opening tag
Throws ThreadException when the thread cannot start.
Method __construct
Create a thread.
This method does not start the thread. This method does not yield.
Param callable $callable The thread body. Param mixed $args Arguments for the thread body.
Method __debugInfo
Return debug information for var_dump.
Method detach
Stop waiting for the thread.
RSHUTDOWN joins the thread later. Do not call wait after this method. This method does not yield.
Method getExitStatus
Return the exit status of the thread.
The status is 0 for a normal return, N for exit(N), 255 for an uncaught exception, and -1 for a kill.
Method getId
Return the native thread id.
The value is fixed at start and does not change after join. The OS can reuse the id after the thread exits. This method returns 0 before start.
Method isDetached
Return true after detach was called.
Method isRunning
Return true while the thread is running.
Method isStarted
Return true after start was called.
Method kill
Send an asynchronous kill request.
This method does not wait for the thread to exit. The thread stops at the next safe point. A blocking native call completes first. After the kill the status is -1. Call wait to get the result.
Throws ThreadException when the thread is not running.
Method start
Start the thread.
This method waits for the child runtime. In a coroutine, this method suspends the current coroutine. Do not call this method twice. A second call throws ThreadException.
Param int $timeout timeout in milliseconds, -1 waits forever
Throws ThreadException when the thread cannot start or the wait times out.
Method wait
Wait for the thread to exit.
A later call returns the cached result. A fatal error in the body gives status 255.
context switching will happen here
Param int $timeout timeout in milliseconds, -1 waits forever
Returns mixed the return value of the body, or null after a fatal error
Throws ThreadException when the wait times out, the thread was killed, or the thread was detached. Throws \Throwable the exception that the thread body threw