gatewaker http 中如何实现延时而不影响程序运行
public static function onWorkerStart($businessWorker)
{
$inner_http_worker = new Worker('http://0.0.0.0:7080');
$inner_http_worker->onMessage = function($http_connection, $data) use ($mqtt,$exporter,$http){
$http_connection->send('');
$_POST = $_POST ? $_POST : $_GET;
$message = @$_POST['msg'];
$ident = @$_POST['ident'];
$operator = @$_POST['operator'];
if($operator == 'EditPerson') sleep(2);
``` $payload['info'] = $message;
if(isset($payload['info']['picURI'])){
$payload['info']['picURI'] = urlencode($payload['info']['picURI']);}
if(isset($payload['info']['path'])){
$payload['info']['path'] = urlencode($payload['info']['path']);}
$payload = json_encode($payload, JSON_UNESCAPED_UNICODE);
$payload = urldecode($payload);
$options['qos'] = 2;
var_dump($payload);
$mqtt->publish($ident,$payload,$options);
};
RT
这个代码因为某些原因,需要后面的操作延时2秒执行,我写了sleep(2),新的数据post进来要等两秒以后。
我想要的结果是后面的操作延时2秒执行,但同时可以接收新的post 数据。
1个回答
年代过于久远,无法发表回答
用定时器
http://doc.workerman.net/timer/add.html