ConsoleReaderThread
extends Thread
in package
Specialized Thread class aimed at PocketMine-MP-related usages. It handles setting up autoloading and error handling.
Note: You probably don't need a thread unless you're doing something in it that's expected to last a long time (or indefinitely). For CPU-demanding tasks that take a short amount of time, consider using AsyncTasks instead to make better use of the CPU.
Table of Contents
- $composerAutoloaderPath : string|null
- $isKilled : bool
- $buffer : Threaded
- $classLoaders : Threaded|null
- $notifier : SleeperNotifier|null
- __construct() : mixed
- getClassLoaders() : array<string|int, ClassLoader>
- getThreadName() : string
- quit() : void
- Stops the thread using the best way possible. Try to stop it yourself before calling this.
- registerClassLoaders() : void
- Registers the class loaders for this thread.
- run() : void
- setClassLoaders() : void
- start() : bool
- onRun() : void
- runSubprocess() : void
- This pile of shit exists because PHP on Windows is broken, and can't handle stream_select() on stdin or pipes properly - stdin native triggers stream_select() when a key is pressed, causing it to get stuck in fgets() waiting for a line that might never come (and Windows doesn't support character-based reading either), and pipes just constantly trigger stream_select() instead of only when data is returned, rendering it useless.
Properties
$composerAutoloaderPath
protected
string|null
$composerAutoloaderPath
$isKilled
protected
bool
$isKilled
= false
$buffer
private
Threaded
$buffer
$classLoaders
private
Threaded|null
$classLoaders
= null
$notifier
private
SleeperNotifier|null
$notifier
Methods
__construct()
public
__construct(Threaded $buffer[, SleeperNotifier|null $notifier = null ]) : mixed
Parameters
- $buffer : Threaded
- $notifier : SleeperNotifier|null = null
Return values
mixed —getClassLoaders()
public
getClassLoaders() : array<string|int, ClassLoader>
Return values
array<string|int, ClassLoader> —getThreadName()
public
getThreadName() : string
Return values
string —quit()
Stops the thread using the best way possible. Try to stop it yourself before calling this.
public
quit() : void
Return values
void —registerClassLoaders()
Registers the class loaders for this thread.
public
registerClassLoaders() : void
WARNING: This method MUST be called from any descendent threads' run() method to make autoloading usable. If you do not do this, you will not be able to use new classes that were not loaded when the thread was started (unless you are using a custom autoloader).
Return values
void —run()
public
final run() : void
Return values
void —setClassLoaders()
public
setClassLoaders([array<string|int, ClassLoader> $autoloaders = null ]) : void
Parameters
- $autoloaders : array<string|int, ClassLoader> = null
Return values
void —start()
public
start([int $options = PTHREADS_INHERIT_NONE ]) : bool
Parameters
- $options : int = PTHREADS_INHERIT_NONE
Return values
bool —onRun()
protected
onRun() : void
Return values
void —runSubprocess()
This pile of shit exists because PHP on Windows is broken, and can't handle stream_select() on stdin or pipes properly - stdin native triggers stream_select() when a key is pressed, causing it to get stuck in fgets() waiting for a line that might never come (and Windows doesn't support character-based reading either), and pipes just constantly trigger stream_select() instead of only when data is returned, rendering it useless.
private
runSubprocess(Threaded $buffer, SleeperNotifier|null $notifier) : void
This results in whichever process reads stdin getting stuck on shutdown, which previously forced us to kill the entire server process to make it go away.
To get around this problem, we delegate the responsibility of reading stdin to a subprocess, which we can then brutally murder when the server shuts down, without killing the entire server process. Thankfully, stream_select() actually works properly on sockets, so we can use them for inter-process communication.
Parameters
- $buffer : Threaded
- $notifier : SleeperNotifier|null