从 php 关闭 nusoap,不要等待结果

发布于 2024-08-01 17:12:33 字数 272 浏览 3 评论 0 原文

我有一个脚本,当前有一个步骤,在客户注册后触发语音广播。 这是对 callfire 的 nusoap 调用。

那里的延迟相当高,并且在我的亚秒级注册过程中增加了大约 2 秒。 结果,我让人们不止一次地点击注册按钮。

有没有办法告诉应用程序不要等待结果并继续前进?

可以通过将所有 nusoap 代码放在一个单独的文件中,然后打开该文件的套接字来进行欺骗,但我正在寻找一种更干净的方法。

或者有没有办法触发函数而不等待结果? 我认为不存在。

I have a script that currently has a step where I trigger a voice broadcast after a customer signs up. It's a nusoap call to callfire.

The latency there is rather high, and it's added about 2 seconds to my sub-second sign up process. As a result, I have people hitting the sign up button more than once.

Is there a way to tell the app to NOT wait for the results and just move on?

It's possible to cheat by putting all of the nusoap code in a separate file, then open a socket to that file, but I'm looking for a cleaner way.

Or is there a way to fire off a function and not wait for the results? I don't think there is.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

‘画卷フ 2024-08-08 17:12:36

据我所知,没有办法直接触发函数并在执行链中越过它......但是有一些很酷/简单的解决方案:

  • 正如您所提到的,将代码放在单独的文件中并触发就这样...虽然我只是使用 shell_exec 命令来运行它并 nohup 它所以它在后台运行
  • 创建一个队列,正如 Paul 提到的
  • 看看像 gearman (http://www.danga.com/gearman/)...Digg 编写了一些不错的 PEAR 库来使用它。 Gearman 可能有点矫枉过正,但它太酷了,更不用说:)

As far as I know there isn't a way to directly fire off a function and move past it in the execution chain... but there are some cool / simple solutions:

  • As you mentioned, putting the code in a separate file and firing it off that way... although I'd just use a shell_exec command to run it and nohup it so it ran in the background
  • Create a queue as Paul mentioned
  • Look into something like gearman (http://www.danga.com/gearman/)... Digg wrote some nice PEAR libs for working with it. Gearman's probably a bit overkill, but it's too cool not to mention :)
再可℃爱ぅ一点好了 2024-08-08 17:12:36

您可能会考虑从浏览器执行一些 Ajax 请求:

  • 用户登录后
  • 会被重定向到该页面上的某个页面(例如,他的帐户页面)
  • ,对服务器上的 PHP 脚本进行 Ajax 调用,该脚本执行 SOAP 我认为

这是您经常听到的一个想法...但它要求用户启用 Javascript,并且可能并不总是能很好地工作(如果用户在 Ajax 请求完成之前离开页面怎么办?)

恕我直言,最好的(更安全,始终有效,不依赖于客户端,...)方式实际上是使用一些请求队列,例如保罗建议

这就是我选择的解决方案。

但是,当然,它会在用户登录和发送请求之间增加一些延迟......但这有那么糟糕吗?

You might think about doing some Ajax request from the browser :

  • user signs in
  • he is redirected to a page (his account page, for instance)
  • on that page, there is an Ajax call to a PHP script on your server, that does the SOAP call

That's an idea that you'll often hear, I think... But it requires the user to hava Javascript enabled, and might not always work nice (what if the user leaves the page before the Ajax request is finished ? )

IMHO, the best (more secure, will always work, doesn't depend on the client, ...) way would really be with some request queue, like Paul suggested.

That's the solution I'd choose.

But, of course, it adds some delay between the user's signing in, and the time the request is sent... but is it that bad ?

卷耳 2024-08-08 17:12:34

如果您有一些操作必须“很快”而不是“立即”,那么将其添加到某种队列(例如数据库表)。

接下来,每隔一分钟左右就会出现一个 cron 作业,并执行此队列中的任务。

If you have some action which just has to be "soon" rather than "right away", then add it to a queue of some sort (e.g. a database table).

Next, have a cron job come along every minute or so and perform tasks that are in this queue.

十年九夏 2024-08-08 17:12:33

您可以将代码移至 cli 脚本。 从 Web 服务器 PHP 线程运行 cli 脚本。 然后 CLI 进程分叉,父进程退出。 Web 线程可以继续,并且 CLI 子进程可以注册用户。

如果 SOAP 调用失败,我建议您将数据存储在某处,并在成功后将其删除或将其标记为已完成。 您可以让 cron 作业定期检查是否有任何调用失败,然后重试,然后通知某人(管理员、用户)。

You can move the code to a cli script. Run the cli script from the web server PHP thread. The CLI process then forks, and the parent exits. The web thread can continue and the CLI child process can sign up the user.

In case of failure wih the SOAP call, I suggest you store the data somewhere and remove it or mark it as finished once is successfull. You can have a cron job routinely check to see if any calls failed, and retry them then notify someone (admin, user).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文