0

Here's my scenario. During signup for my app - i trigger a few PHP method calls that are long running (e.g. get UserFriendLikes, etc using OpenGraph API).

I want the methods to run in the background without the user noticing it - and leave the method to complete at its own time.

Whats the best way to acheive it? Does just calling longRunningMethod() from the user signup page work - or is there anything else i need to do to ensure that it is not terminated when user navigates to another page, etc?

4

2 に答える 2

4

I would create a new process using a shell exec. Something like this should work:

shell_exec("./scriptname.php > /dev/null 2>/dev/null &");

It will start a new process I believe and continue execution on the calling page, allowing the user to continue as usual.

于 2012-10-31T01:19:34.010 に答える
3

上記のTim Sのソリューションは機能しますが、スケーリングが困難になります。別の方法として、作業要求をキューに入れ、そこでワーカー プログラムによって取得され、処理されるようにすることもできます。つまり、サインアップ ページがキューにドロップされるだけで、ユーザーは自由に他のページに移動できます。

RabbitMQのようなワーク キューを見てください。これについて説明し、問題の解決に役立つように思われるドキュメントの単語を次に示します。

ワーク キュー (別名: タスク キュー) の背後にある主なアイデアは、リソースを集中的に使用するタスクをすぐに実行して、完了するまで待たなければならないことを回避することです。代わりに、タスクを後で実行するようにスケジュールします。

自分で Rabbit MQ をセットアップしたくない場合は、Iron.ioでワーカーにサインアップしてみてください。無料のアカウントが付属していると思います。

于 2012-10-31T01:36:41.757 に答える