我在for
循环中使用pusher-http-php发送了消息。 $pusher->trigger
调用等待返回继续。没有Pusher消息,循环需要2-3秒。通过trigger
调用,它会导致504错误,并且在数据库中需要超过半小时。
有没有办法在PHP中异步发送这些消息?
答案 0 :(得分:0)
你是对的the $pusher->trigger
method向Pusher发出同步HTTP请求。您可以使用$pusher->triggerBatch
来减少网络延迟。
如果你真的想让$pusher->trigger
异步,你可以把它包装在异步任务中。 Here's an introduction to async PHP