PHP code example of tapat4n / fork
1. Go to this page and download the library: Download tapat4n/fork 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/ */
tapat4n / fork example snippets
use Tapat4n\Fork\ForkManager;
use Tapat4n\Fork\Message\MessageInterface;
$manager = new ForkManager();
$i = 0;
$manager->addWorker(function (MessageInterface $message) use ($i) {
$message->set(++$i);
});
$manager->addWorker(function (MessageInterface $message) use ($i) {
$content = '';
while ($i < 1000) {
$content .= $i;
$i++;
}
$message->set($content);
}, true); // set true to detach process
$manager->dispatch();
var_dump($manager->getMessages());
var_dump($manager->getMessagesContent());