PHP code example of milanowicz / php-thread

1. Go to this page and download the library: Download milanowicz/php-thread library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

milanowicz / php-thread example snippets


$thread = new Milanowicz\Thread\Threads();
$thread->exec('php scripts/script1.php');
$thread->exec('php scripts/script2.php');
$thread->anyRunning();
$thread->stopAll();
$thread->reset();

$worker = new Milanowicz\Thread\Worker([
    'command' => '/bin/sleep 2',
    'execMaxCounter' => 10, // How many would you execute?
    'maxWorkers' => 2, // How process(es) should be started? 
    'maxExecutionTime' => 120, // Seconds to run php script
    'memoryLimit' => '32M', // Maximum for php memory limit
    'workerDelayStart' => 1, // Delay for starting processes after each other
    'workerRunSleep' => 2, // Sleep to check again if enough processes are running
]);
$worker->setCheckDispatcher(function () { return <bool>; });
$worker->run(); // Main call to start worker loop

$worker->getThread(); // Get current Thread instance

$singleton = new Milanowicz\Thread\ThreadSingleton();
$singleton->exec('php scripts/script1.php');
$singleton->exec('php scripts/script2.php');
$singleton->anyRunning();
$singleton->stopAll();
$singleton->reset

$worker = new Milanowicz\Thread\Worker([
    'command' => '/bin/sleep 20',
    'execMaxCounter' => 10, // How many would you execute?
    'maxWorkers' => 2, // How process(es) should be started?
], new Milanowicz\Thread\ThreadSingleton());
$worker->run();
shell
> composer