The Slim Framework support forum has moved to This Tender forum is no longer maintained or monitored.

Get http response and then continue process

Hardik Dave's Avatar

Hardik Dave

18 Aug, 2015 07:34 AM

I am sending a downloadable file url to slim restful api. Once the file is downloaded on my server, I want to send the user a response as
{status:"done"} and then start processing in the backend.

i.e. I want to echo the response and then initiate my process on the server. I am new to slim and have been trying redirect ob_flush etc. Could anyone please help?

  1. Support Staff 1 Posted by Rob Allen on 18 Aug, 2015 08:47 AM

    Rob Allen's Avatar

    I don't think you can do what you want to do as the PHP process finishes when the response is sent to the browser.

    The usual solution to this problem is to use a queue like RabbitMQ or Gearman

  2. 2 Posted by Hardik Dave on 18 Aug, 2015 01:05 PM

    Hardik Dave's Avatar

    Sir, I have got Gearman, I am able to run background jobs and normal ones too. I wanted to know:
    1. How does gearman queue request?
    2. Could I get the status of a particular request (Queued, Processing,Completed)?
    3. How can rate limiting be executed?

    I am trying to do the following:

    1. Send file url - and response to the user
    2. Processing the file - long running jobs (should be queued if needed)
    3. GET status of the process

    Any help to startoff would be appreciated.

  3. 3 Posted by Pablo on 23 Jun, 2016 10:36 AM

    Pablo's Avatar

    My solution:

    As a middleware:

                $this->responseAndContinue('whatever_content' , 200),
                function () use ($app) {
                 //Code ......


    private function finishHere($content,$status){
            ob_end_flush(); // This line does the trick
            header("Connection: close");
            header("HTTP/1.0 $status " . HttpStatusCode::get($status));
            header('Content-type: application/json; charset=utf-8');
            ignore_user_abort(); // optional
            echo $content;
            $size = ob_get_length();
            header("Content-Length: $size");
            ob_end_flush(); // Again for print content
            flush(); // Unless both are called !

         * Finish response and continue
         * @return session finish
        protected function responseAndContinue($content,$status){
            return function ($route) use ($content,$status) {

  4. Josh Lockhart closed this discussion on 12 Feb, 2021 07:37 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac