1. Go to this page and download the library: Download recoil/recoil 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/ */
recoil / recoil example snippets
use Recoil\React\ReactKernel;
use Recoil\Recoil;
function resolveDomainName(string $name, React\Dns\Resolver\Resolver $resolver)
{
try {
$ip = yield $resolver->resolve($name);
echo 'Resolved "' . $name . '" to ' . $ip . PHP_EOL;
} catch (Exception $e) {
echo 'Failed to resolve "' . $name . '" - ' . $e->getMessage() . PHP_EOL;
}
}
ReactKernel::start(function () {
// Create a React DNS resolver ...
$resolver = (new React\Dns\Resolver\Factory)->create(
'8.8.8.8',
yield Recoil::eventLoop()
);
// Concurrently resolve three domain names ...
yield [
resolveDomainName('recoil.io', $resolver),
resolveDomainName('php.net', $resolver),
resolveDomainName('probably-wont-resolve', $resolver),
];
});
function multiply($a, $b)
{
yield; // force PHP to parse this function as a generator
return $a * $b;
echo 'This code is never reached.';
}
ReactKernel::start(function () {
$result = yield multiply(2, 3);
echo '2 * 3 is ' . $result . PHP_EOL;
});
function multiply($a, $b)
{
if (!is_numeric($a) || !is_numeric($b)) {
throw new InvalidArgumentException();
}
yield; // force PHP to parse this function as a generator
return $a * $b;
}
ReactKernel::start(function() {
try {
yield multiply(1, 'foo');
} catch (InvalidArgumentException $e) {
echo 'Invalid argument!';
}
});
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.