Multi-threading in Symfony2

Viewed 10488

I have a bit of situation here. I'm using symfony2 and facebook SDK to set up a web service for my IPhone and Android applications. The problem is that the background work can take quite a while. User is first redirected to facebook login page where he can proceed by accepting my facebook app permissions. So, instead of waiting for my service to complete background work, user should be notified immediately that everything is in order. Service should continue work in background and user should be unaware of it. This is the relevant part of controller action:

public function persistPostsAction() {

    ...
    if ($this->CheckUser($user_id) == 0) {
/*This function should be called on background thread*/
    $this->persistPosts($user_id);
    }

    ...

    return $this->render('FacebookAPIFacebookBundle:Page:postovi.html.twig', array(
                'FacebookPosts' => $pwu
    ));
}

How can I call $this->persistPosts($user_id); function on another thread and then just continue with execution? What is the best practice for this kind of problem?

2 Answers
Related