简体   繁体   English

为PHP发送异步消息Pusher HTTP API

[英]Sending asynchronous message Pusher HTTP API for PHP

I have messages being sent with pusher-http-php inside a for loop. 我在for循环中使用pusher-http-php发送消息。 The $pusher->trigger call waits for a return to go on. $pusher->trigger调用等待返回继续。 The loop takes 2-3 seconds without the Pusher messages. 没有Pusher消息,循环需要2-3秒。 With the trigger call, it causes a 504 error and it takes over half an hour in the database. 使用trigger调用,它会导致504错误,并且在数据库中需要超过半小时。 Is there a way to send these messages asynchronously in PHP? 有没有办法在PHP中异步发送这些消息?

You're right that the $pusher->trigger method makes a synchronous HTTP request to Pusher. 你是对的, $pusher->trigger方法向Pusher发出同步HTTP请求。 You could use $pusher->triggerBatch to cut down on the network latency. 您可以使用$pusher->triggerBatch来减少网络延迟。

If you really want to make $pusher->trigger asynchronous, you could wrap it in an asynchronous task. 如果你真的想让$pusher->trigger异步,你可以把它包装在异步任务中。 Here's an introduction to async PHP . 这是异步PHP的介绍

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM