我有一个脚本,当前有一个步骤,在客户注册后触发语音广播。 这是对 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.
发布评论
评论(4)
据我所知,没有办法直接触发函数并在执行链中越过它......但是有一些很酷/简单的解决方案:
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:
您可能会考虑从浏览器执行一些 Ajax 请求:
这是您经常听到的一个想法...但它要求用户启用 Javascript,并且可能并不总是能很好地工作(如果用户在 Ajax 请求完成之前离开页面怎么办?)
恕我直言,最好的(更安全,始终有效,不依赖于客户端,...)方式实际上是使用一些请求队列,例如保罗建议。
这就是我选择的解决方案。
但是,当然,它会在用户登录和发送请求之间增加一些延迟......但这有那么糟糕吗?
You might think about doing some Ajax request from the browser :
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 ?
如果您有一些操作必须“很快”而不是“立即”,那么将其添加到某种队列(例如数据库表)。
接下来,每隔一分钟左右就会出现一个 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.
您可以将代码移至 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).