Welcome Guest, Not a member yet? Register   Sign In
Using flush in controller, return echo before running script
#1

[eluser]Unknown[/eluser]
Hi,

I would first like to say hello, this is my first post here and hopefully one of many while I learn code igniter.

I have got a controller that on a form submit runs a php function, however I am trying to have it echo by using a flush that will echo to the user before the script is finished (as the script can take a few minutes to run) I am then using ignore_user_abort(); to ignore the user closing the window or leaving.

However after submitting the form it still does not echo until the script has finished and I am unsure why, here is my controller function:

Code:
function harvest()
{

  $this->data['title'] = "Harvest";

  if (!$this->ion_auth->logged_in())
  {
   redirect('account', 'refresh');
  }


  if ($this->form_validation->run() == true) {
  
   echo "We are now harvesting your users, we will email you the results.";
   ignore_user_abort(true);
   set_time_limit(0);
   flush();
  
   Now I have a load of script here that is doing my main function that takes around 10 minutes


  } else {

   //display the create user form
   //set the flash data error message if there is one
   $this->data['message'] = (validation_errors() ? validation_errors() : ($this->ion_auth->errors() ? $this->ion_auth->errors() : $this->session->flashdata('message')));

   $this->data['keyword'] = array(
    'name'  => 'keyword',
    'id'    => 'keyword',
    'type'  => 'text',
    'value' => $this->form_validation->set_value('keyword'),
   );
    
   $this->load->view('farm/harvest', $this->data);

   }

When I submit my form it just loads the page for a good few minutes then finally shows my echo as well as completing the action. I would ideally like it just to echo to the user that they are free to leave before running the script so they don't have to stick around for their email.

Any help is greatly appreciated,
Thanks,
Simon


Messages In This Thread
Using flush in controller, return echo before running script - by El Forum - 10-08-2013, 08:10 AM



Theme © iAndrew 2016 - Forum software by © MyBB