在节俭异步函数回调? [英] Callbacks in Thrift Asynchronous Functions?

查看:156
本文介绍了在节俭异步函数回调?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

节俭的有可能的使用的单向的修改指定调用作为的异步

显然,它不可能以限定的回调的,不过,也可以当完成功能的执行中执行

Apparently, it's not possible to define a callback, though, to be executed when the execution of the function is completed.

看来,我唯一的可能性就是给我的储蓄客户端( PHP )一些服务器功能,这样一来,当沉重的计算是在服务器端完成,我可以送通知给它。这意味着,我应该有一个新的.thrift文件,用新的定义,新的服务和所有的休息,我应该产生PHP的服务器端code。与节俭。

It seems that the only possibility I have is to give my Thrift client (PHP) some "server" capabilities, so that, when the heavy computation is completed on the server side, I can send a notification to it. This means that I should have a new .thrift file, with new definitions, new services and all the rest and that I should generate php-server side code with Thrift.

即使这是可行的,它看起来像矫枉过正我,我不知道是否有实现的回调更聪明的方法。

Even if this is feasible, it looks like an overkill to me and I'm wondering if there's a more clever way to implement the callback.

期待着一些反馈从你们,伙计们。

Looking forward for some feedback from you, guys.

推荐答案

罗伯托,不幸的是节俭框架有没有这样的内置功能。有可能是一个数字替代,不过,这取决于你希望你的PHP客户端会话期间,您通常会已经等待了计算密集型节俭服务器回答的时候做什么(有你没用过单向

Roberto, unfortunately the Thrift framework has no such built-in functionality. There may be a number of alternatives, though, depending on what you want your PHP client session to do during the time you would normally have waited for the computationally-intensive Thrift server to answer (had you not used oneway.)

我只能想象,现在,你是在一个情况下,有codeD的Web应用程序,其中一个用户(或几个并联的用户)可以在每个触发一个计算密集的任务,你想提供一些反馈用户,同时表示任务一起翻腾地说道。

I can only imagine, for now, that you are in a situation where, having coded a web application where a user (or several users in parallel) can each trigger a computationally-intensive task, you would like to provide some feedback to said users while said tasks churn along.

从一开始,你是在试图避免你正试图避免该解决方案完全正确。你的PHP客户端会话的不阻塞不能服务回调接口(除非你挖你的孔更深,试图使用的 pcntl_fork 或其他<一href=\"http://www.phpclasses.org/package/1136-PHP-A-class-to-implement-multi-threaded-applications.html\">PHP线程创可贴。)

From the start, you are absolutely right in trying to avoid the solution that you are trying to avoid. Your PHP client sessions cannot service a callback interface without blocking (unless you dig your hole even deeper by trying to use pcntl_fork or some other PHP threading band-aid.)

出这种最简单,恕我直言,最好的办法是两个从事件驱动的模型开关我想通知当服务器完成的)的到轮询模式我将定期与服务器询问它是否做的)。有实现轮询模型的方法有多种,有多个实施方案的服务器上,以及作为在客户端侧,如:

The simplest and IMHO best way out of this is two switch from an event-driven model (I want to be notified when the server is done) to a polling model (I will periodically inquire with the server whether or not it is done.) There are several ways of implementing a polling model, with multiple implementation options on the server as well as on the client sides, such as:


  1. 调用相


  • PHP客户端会话分配一个唯一的作业ID 值;会议则使得异步单向通话无效计算(...,JOB_ID)到计算密集型服务器节俭

  • the PHP client session allocates a unique job_id value; the session then makes the asynchronous oneway call void compute(..., job_id) to the computationally-intensive Thrift server,

- 或 -

-- or --


  • PHP客户端会话发出的同步的通话 JOB_ID start_compute(...)的计算密集型节俭服务器;服务器分配唯一的作业ID 值,然后产卵在一个单独的线程/进程的实际计算密集型任务,回到马上到PHP客户端会话与分配作业ID

  • the PHP client session makes a synchronous call job_id start_compute(...) to the computationally-intensive Thrift server; the server allocates the unique job_id value, then spawns the actual computationally-intensive task in a separate thread/process, returning right away to the PHP client session with the allocated job_id

计算相


  • PHP客户端会话进行定期通过的同步状态GET_STATUS(JOB_ID)打电话到检查计算密集型作业的状态计算密集型节俭服务器,

  • the PHP client session proceeds to periodically check the status of the computationally-intensive job via a synchronous status get_status(job_id) call to the computationally-intensive Thrift server,

- 或 -

-- or --


  • PHP客户端会话立即终止以腾出precious资源,通过对作业ID 浏览器,并指示浏览器定期检查后,在计算密集型工作作业ID (例如通过 META REFRESH ,或通过从Javascript的XHR(AJAX)要求等);浏览器检查派生它执行一个简单的PHP客户端会话中的同步状态GET_STATUS(JOB_ID)打电话到计算密集型节俭服务器后,立即终止转发上的状态(取可能),以在浏览器

  • the PHP client session terminates right away in order to free up precious resources, after passing on the job_id to the browser and also instructing the browser to periodically check the status of the computationally-intensive job job_id (e.g. via META REFRESH, or via an XHR (AJAX) request from Javascript, etc.); the browser check spawns a brief PHP client session which performs the synchronous status get_status(job_id) call to the computationally-intensive Thrift server, terminating immediately after forwarding the status (whichever it may be) on to the browser

这篇关于在节俭异步函数回调?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆