PHP code example of wyrihaximus / parallel-runtime
1. Go to this page and download the library: Download wyrihaximus/parallel-runtime 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/ */
wyrihaximus / parallel-runtime example snippets
declare(strict_types=1);
use WyriHaximus\Parallel\Runtime;
use function trigger_error;
use const WyriHaximus\Constants\ComposerAutoloader\LOCATION;
$runtime = new Runtime(LOCATION);
$future = $runtime->run(static function (): string {
trigger_error('Error! Error! Error!');
return 'yay';
});
posix_kill(posix_getpid(), SIGUSR1);
$outcome = $future->value();
echo get_class($outcome), PHP_EOL; // WyriHaximus\Parallel\Outcome
echo $outcome->result(), PHP_EOL; // yay
foreach ($outcome->errors() as $error) {
echo $error->message(), PHP_EOL; // Error! Error! Error!
}
foreach ($outcome->signals() as $signal) {
echo $signal->signal(), PHP_EOL; // SIGUSR1
}