Download the PHP package byjg/phpthread without Composer
On this page you can find all versions of the php package byjg/phpthread. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download byjg/phpthread
More information about byjg/phpthread
Files in byjg/phpthread
Package phpthread
Short Description Polyfill Implementation of Threads in PHP. This class supports both FORK process and native Threads using ZTS compilation.
License MIT
Informations about the package phpthread
phpthread
Polyfill Implementation of Threads in PHP. This class supports both FORK process and native Threads using ZTS compilation;
This class detects automatically if PHP was compiled:
- with ZTS (--enable-maintainer-zts or --enable-zts) and the extension pthreads (works on Windows also)
- with the Process Controle (--enable-pcntl)
and choose the most suitable handler for processing the threads. The thread interface is the same whatever is the Thread handler.
Notes
- Most of the fork implementation was based on the post "http://villavu.com/forum/showthread.php?t=73623" by the "superuser"
- Tales Santos (tsantos84) contributed on the base of the Thread ZTS by creating the code base and solving some specific thread problems. Thanks!!!!
Usage
Assume for the examples below the class 'Foo' and the method 'bar':
Basic Thread Usage
Thread Pool Usage
You can create a pool of threads. This is particulary interesting if you want to queue Workers after the pool is started.
Important Note for the FORK implementation
In order to get working the 'getResult' of the fork implementation is necessary pass the setup parameters to the Thread::setThreadHandlerArguments() method;
Install
Just type: composer require "byjg/phpthread=2.3.*"
Major changes from 1. to 2.
- Method Thread::start() renamed to Thread::execute()
- Implemented PThread and Fork as a Polyfill class
FAQ
How do I instantiate a method class?
or