0

I am new to background processes in Codeigniter. I thought CURL would help me in executing a method name.

Basically, My website is sending a mail to admin(me) whenever an user drops a msg. My controller method inserts in the database and executes Curl library (calls another method name) for background execution so that user doesn't have to wait until the mail has been sent. I tried CURL library by Phil Sturgeon but my hard luck.

Help appreciated. Thanks a lot.

Chopra
  • 571
  • 4
  • 8
  • 23

1 Answers1

0

curl is not going to run a method in the background. If you want to run background jobs in php, you would need to use the command line / exec().

However, a more solid way to add jobs in the background - if sending mail really takes that long - would be to add the message to a message queue in a database and schedule a job (using cron on linux for example) that checks the queue periodically for messages to be sent.

jeroen
  • 91,079
  • 21
  • 114
  • 132
  • Thanks. I want mail to be sent as soon as the user drops a message. I'll try exec() as u said. I hope it executes methods also. – Chopra Jun 05 '14 at 16:55
  • @DixitChopra You can start php in your exec call, see for example http://stackoverflow.com/questions/14555971/php-exec-background-process-issues – jeroen Jun 05 '14 at 16:57
  • How about command-line interface? http://ellislab.com/codeigniter/user-guide/general/cli.html – Chopra Jun 05 '14 at 17:04
  • @DixitChopra That is what you would have to use if you need the whole framework; use `exec()` to start CodeIgniter from the command line in the background. Otherwise you can just start a simple php script using `exec()` in the background. – jeroen Jun 05 '14 at 17:06