AzaThread flexibly adjusts for any of your tasks. There are two static parameters which affects all the threads and many parameters affecting each individual thread.
The standard way to specify settings - override a class property:
class ExampleThread extends Thread
{
protected $prefork = false; // Turn off preforking
function process()
{
// ...
}
}
The second variant - is to send an array of settings. This method is intended for closures, but can be used with regular classes.
$thread = SimpleThread::create(function() {
// ...
}, array(
'timeoutMasterResultWait' => 15, // Set the timeout for waiting for the result in 15 seconds
));
$thread = new ExampleThread(null, null, null, array(
'timeoutMasterResultWait' => 15, // Set the timeout for waiting for the result in 15 seconds
));
Most options are not checked at the processing time, so changing property values after creating the "thread" instance does not make sense.
Default value -true
.
Flag. Enables waiting for next tasks in thread. If disabled, then after one task child process dies.
Preforked threads ($prefork = true
) are always multitask.
Default value -true
.
Flag. Enables listening for all POSIX signals in parent process. SIGCHLD is always listened - it is required for normal functioning.
More information about signals processing in the both parent and child processes can be read in the relevant part of the documentation.
Default value -true
.
Flag. Enables pre-forking, to avoid wasting resources later. The process is forked directly at the creation of the instance. This allows more efficient initialization (especially in pools).
Preforked threads are always multitask.
Default value -false
.
Flag. Enables forced wait for the pre-forking child. This allows you to save one call to wait
method before running the task, but it takes away all the effectiveness of pre-provisioning. So it is not recommended to use.
Default value -false
.
Flag. Enables mapping of arguments for the process
method. So you can get arguments as in usual function, not only through the getParam
/getParams
:
class ExampleThread extends Thread
{
protected $argumentsMapping = true;
function process($arg1, $arg2)
{
echo $arg1; // 12
echo $arg2; // 79
}
}
$thread = new ExampleThread();
$thread->wait()->run(12, 79);
Creates a little performance overhead, so disabled by default.
Default value -3
.
Timeout. Maximum timeout for master to wait for worker initialization (prefork) (in seconds, can be fractional).
Set to a negative value (-1
) to disable.
Default value -5
.
Timeout. Maximum timeout for master to wait for the job results (in seconds, can be fractional).
Set to a negative value (-1
) to disable.
Default value -600
.
Timeout. Maximum timeout for worker to wait for the new job (in seconds, can be fractional). After it spawned child will die.
Set to a negative value (-1
) to disable.
Default value -5
.
Interval. Interval for worker to check master process (in seconds, can be fractional). If it's not successfull child will die.
Can not be turned off. If incorrect then default value will be used.
Serialization mode for transferring data between processes. By default, the php serialization is used. If igbinary extension is available, then it is automatically used. Not recommended to change the value manually.
Availability flag for the full feature mode. Automatically set to true
, if all dependencies are available. Если установлено в `` ложной, то «нити» будет использовать синхронный режим совместимости. You can turn it on, if you want to test the functionality in a simplified synchronous mode without forking.