1. Go to this page and download the library: Download alanalbert/php-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/ */
alanalbert / php-async example snippets
use Async\DaemonProcess;
use Async\Job;
// 异步操作任务
$job = new Job();
// 设置异步任务
$job->setJob(function () {
sleep(5);
});
// 设置回调函数
$job->setCallback(function () {
file_put_contents('处理完成.txt', '处理完成');
});
// 实例化异步进程
$daemon = new DaemonProcess($job);
$daemon->run();