Prathima J
Prathima J

Reputation: 21

how to execute a codeigniter controller method in background

I have a codeigniter's controller function that fetches mails from gmail.

It is taking lot of time so I need to execute that particular controller function in the background so that the user need not wait until all the mails are fetched.

Upvotes: 2

Views: 2048

Answers (1)

Daniel Krom
Daniel Krom

Reputation: 10058

Ajax Jquery Way

js:

$.ajax({
    url   : "index.php?/MyController/myMethod",
    async : true //change this to false if you hate your users and want them to wait 
}).done(function() {
    alert("EMAIL IS READY! USER DIDN'T WAIT")
});

php:

class MyController extends CI_Controller{

      function myMethod(){
          //do your email stuff
      }

      //if codgeIgniter V2
      function myMethod_get(){
          //do your email stuff
      }

}

Upvotes: 1

Related Questions