Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8460333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:34:41+00:00 2026-06-10T13:34:41+00:00

I have a lengthy import process and I am trying to use the new

  • 0

I have a lengthy import process and I am trying to use the new StreamedResponse available in Symfony 2.1 to report some feedback about the task to the user but the response is not being streamed (I get all the content at once at the end of processing). This is my code in my controller:

            $em = $this->getDoctrine()->getEntityManager();
            $response = new StreamedResponse();
            $response->setCallback(function () use ($em) {
                $file = fopen(sys_get_temp_dir().'/categories.txt', 'r');
                $lineNum = 0;
                while ($line = fgets ($file)) {
                    $category = new Category();
                    $fields = explode("\t",$line);
                    $category->setFullId($fields[0]);
                    $category->setName($fields[2]);
                    $category->setFullName($fields[4]);
                    $em->persist($category);
                    if ($lineNum%100==0) {
                        echo 'Processing Line: '.$lineNum.'<br>';
                        flush();                            
                        $em->flush();
                    }
                    $lineNum++;
                }
                fclose($file);
            });
            return $response;                 

Any idea what may be wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T13:34:42+00:00Added an answer on June 10, 2026 at 1:34 pm

    OK, I found it: you need to call both ob_flush() and flush().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use scala parallel collections to implement some cpu-intensive task, I've wanted
I have a console app that performs a lengthy process. I am printing out
The book, Producing Open Source Software , suggests that it's better to have lengthy
I have a lengthy JavaScript file that passes JSLint except for used before it
Suppose I have a polygon ( a lengthy rectangle ) made up of several
I've got a rather lengthy query i have been working with that is throwing
I have 2 equal-length lists and I am trying to get scalar product of
I'm in the process of setting up a background task that makes network calls;
Let me start by saying, I am new to Java programming. I have coded
In an attempt to organize my code, I'm trying to split up my (lengthy)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.