1. Go to this page and download the library: Download rdlowrey/alert 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/ */
rdlowrey / alert example snippets
use Revolt\EventLoop;
Suspension();
EventLoop::delay(5, function () use ($suspension): void {
print '++ Executing callback created by EventLoop::delay()' . PHP_EOL;
$suspension->resume(null);
});
print '++ Suspending to event loop...' . PHP_EOL;
$suspension->suspend();
print '++ Script end' . PHP_EOL;
/** @param Closure(mixed $value): mixed $map */
public function map(Closure $map): Future
/** @param Closure(Throwable $exception): mixed $catch */
public function catch(Closure $catch): Future
/** @param Closure(): void $finally */
public function finally(Closure $finally): Future
use Amp\Future;
use Amp\Http\Client\HttpClientBuilder;
use Amp\Http\Client\Request;
ogle.com",
"news" => "https://news.google.com",
"bing" => "https://www.bing.com",
"yahoo" => "https://www.yahoo.com",
];
try {
$responses = Future\await(array_map(function ($uri) use ($httpClient) {
return Amp\async(fn () => $httpClient->request(new Request($uri, 'HEAD')));
}, $uris));
foreach ($responses as $key => $response) {
printf(
"%s | HTTP/%s %d %s\n",
$key,
$response->getProtocolVersion(),
$response->getStatus(),
$response->getReason()
);
}
} catch (Exception $e) {
// If any one of the requests fails the combo will fail
echo $e->getMessage(), "\n";
}
final class DeferredFuture
{
public function getFuture(): Future
public function complete(mixed $value = null): void
public function error(Throwable $throwable): void
}
// Example async producer using DeferredFuture
use Amp\Future;
use Revolt\EventLoop;
// Complete the async result one second from now
EventLoop::delay(1, function () use ($deferred, $x, $y) {
$deferred->complete($x * $y);
});
return $deferred->getFuture();
}
$future = asyncMultiply(6, 7);
$result = $future->await();
var_dump($result); // int(42)
request("...", new Amp\TimeoutCancellation(30));
request("...", new Amp\SignalCancellation(SIGINT));
$deferredCancellation = new Amp\DeferredCancellation();
// Register some custom callback somewhere
onSomeEvent(fn () => $deferredCancellation->cancel());
request("...", $deferredCancellation->getCancellation());
// Creates a callback which is invoked every 0.5s
// unless disabled or the object is destroyed.
$interval = new Interval(0.5, function (): void {
// ...
});
// Disable the repeating timer, stopping future
// invocations until enabled again.
$interval->disable();
// Enable the repeating timer. The callback will
// not be invoked until the given timeout has elapsed.
$interval->enable();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.