Download the PHP package alicemajere/wonderland-thread without Composer
On this page you can find all versions of the php package alicemajere/wonderland-thread. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download alicemajere/wonderland-thread
More information about alicemajere/wonderland-thread
Files in alicemajere/wonderland-thread
Package wonderland-thread
Short Description Simple multi-threading management library
License MIT
Informations about the package wonderland-thread
Wonderland Thread
A small simple multi-threading library to include in projects
Recent Update
The project just got released on packagist with release 1.0.0.
Installation
You need to have composer and autloader installed. To be able to install the package, add this entry in the "repositories" index of your composer.json
Just require the package with composer
Usage
To start a multi-threading Pool, just create a new instance of ThreadPool
We setup a maximum number of Thread to run at the same time. If we add 200 Threads to the Pool, only 5 of them will run at the same time until the Pool processed all the 200 Threads
Add one or more Thread to the Pool by creating a new instance of Thread. A Thread take two parameters, a name and a closure function that will tell the Thread what to do. The closure have to return an exit status from the ones defined in the Thread class constants.
To run the ThreadPool, you can just do
You can add Listeners that will trigger on a particular Event while the Pool is running the Threads. Using Listeners can be useful if you need to do particular things for every Threads, like opening a separate mysql connection for every Thread. A Listener object constructor need the Event name to listen to and a closure function that will tell the Listener what to do for this Event. The full list of Event definition is found in the Event class.
Prerequisites
PHP >= 7.2
Getting help
If you've instead found a bug in the library or would like new features added, go ahead and open issues or pull requests against this repo!
Authors
- Alice Praud - Initial work - AliceMajere
All versions of wonderland-thread with dependencies
ext-pcntl Version *