PHP code example of soen / delay-alone
1. Go to this page and download the library: Download soen/delay-alone 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/ */
soen / delay-alone example snippets
sConfig = [
'host' => '127.0.0.1',
'port' => '6379',
'database' => '0',
'password' => '',
'timeout' => 60
];
s = (new \Soen\Delay\Alone\Redis($redisConfig))->getDriver();
$deplayer = new \Soen\Delay\Alone\Polling(1, $redis);
$deplayer->run();
s = (new \Soen\Delay\Alone\Redis($redisConfig))->getDriver();
$client = new \Soen\Delay\Alone\Client\Client($redis);
//生成随机数 body 数据
$strs="QWERTYUIOPASDFGHJKLZXCVBNM1234567890qwertyuiopasdfghjklzxcvbnm";
$name=substr(str_shuffle($strs),mt_rand(0,strlen($strs)-11),10);
/**
* 随机生成ID,固定topic1, 随机body数据,延迟队列延迟10秒更新
*/
$has = $client->push(rand(1,999),'topic1',['a'=>$name,'b'=>$name],10);
if($has){
echo '数据提交成功'.PHP_EOL;
}else {
echo '提交失败'.PHP_EOL;
}
s = (new \Soen\Delay\Alone\Redis($redisConfig))->getDriver();
$client = new Soen\Delay\Alone\Client\Client($redis);
ini_set('default_socket_timeout', -1);
while (true){
$data = $client->bPop('topic1', 3600);
if(!$data){
continue;
}
var_dump($data);
}