1. Go to this page and download the library: Download drewlabs/async 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/ */
$promise = promise(function($resolve, $reject) {
// Do something with resolve
usleep(1000*1000); // Block PHP execution
resolve("I have been waited for 1 second.");
});
// Wait for the promise
$promise->wait();
// Here the script create a promise instance that executes when
// PHP process shutdown with success
$promise = promise(function($resolve, $reject) {
// Do something with resolve
usleep(1000*1000); // Block PHP execution
resolve("I have been waited for 1 second.");
}, true);
// Here the script create a promise instance that executes when
// PHP process shutdown with success
$promise = defer(function($resolve, $reject) {
// Do something with resolve
usleep(1000*1000); // Block PHP execution
resolve("I have been waited for 1 second.");
});