Thread

You wonder why this is the case?

I created this object class for those who are lazy or do not like to use the PThreads extension available on PHP.

The methods are either sufficient or sufficient to be able to control multithreading in a primitive way.

/**
 * This abstract method use to run the thread
 */
public function onRun(): void;

/**
 * @param array<int, array<string>> $mode
 * @throws ReflectionException
 * @throws Throwable
 * @phpstan-param array<int, array<string>> $mode
 *
 * This method use to start the thread
 */
public function start(array $mode = DescriptorSpec::BASIC) : Promise;

/**
 * @return string
 */
public function getInput(): string;

/**
 * This method use to get the pid of the thread
 */
public function getPid(): int;

/**
 * This method use to get the exit code of the thread
 */
public function getExitCode(): int;

/*
 * This method use to get the running status of the thread
 */
public function isRunning(): bool;

/**
 * This method use to get the signaled status of the thread
 */
public function isSignaled(): bool;

/**
 * This method use to get the stopped status of the thread
 */
public function isStopped(): bool;

/**
 * @return array<string, mixed>
 * @phpstan-return array<string, mixed>
 *
 * This method use to get the shared data of the main thread
 */
public static function getDataMainThread(): array;

/**
 * @param array<string, mixed> $shared
 * @phpstan-param array<string, mixed> $shared
 *
 * This method use to set the shared data of the main thread
 */
public static function setShared(array $shared): void;

/**
 * @param string $key
 * @param mixed $value
 * @phpstan-param mixed $value
 *
 * This method use to add the shared data of the MAIN-THREAD
 */
public static function addShared(string $key, mixed $value): void;

/**
 * @return array<string, mixed>
 *
 * This method use to get the shared data of the child thread
 */
public static function getSharedData(): array;

/**
 * @param array<string, mixed> $data
 * @return void
 * @phpstan-param array<string, mixed> $data
 *
 * This method use to post all data the main thread
 */
public static function postMainThread(array $data): void;

/**
 * @param string $data
 * @return void
 *
 * This method use to load the shared data from the main thread
 */
public static function loadSharedData(string $data): void;

/**
 * @param string $data
 * @return void
 *
 * This method use to alert for the main thread
 */
public static function alert(string $data): void;

/**
 * @param int $pid
 * @return bool
 *
 * This method use to check the thread is running or not
 */
public static function threadIsRunning(int $pid): bool;

/**
 * @param int $pid
 * @return bool
 *
 * This method use to kill the thread
 */
public static function killThread(int $pid): bool;

Last updated