为PHP发送异步消息Pusher HTTP API

时间:2017-06-01 15:36:21

标签: php asynchronous pusher

我在for循环中使用pusher-http-php发送了消息。 $pusher->trigger调用等待返回继续。没有Pusher消息,循环需要2-3秒。通过trigger调用,它会导致504错误,并且在数据库中需要超过半小时。 有没有办法在PHP中异步发送这些消息?

1 个答案:

答案 0 :(得分:0)

你是对的the $pusher->trigger method向Pusher发出同步HTTP请求。您可以使用$pusher->triggerBatch来减少网络延迟。

如果你真的想让$pusher->trigger异步,你可以把它包装在异步任务中。 Here's an introduction to async PHP