Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Phalcon cli process

I am new to phalcon..Trying to run background process for sending mail.... In terminal command "php app/cli.php main" is working properly ..But how can I make it to run from controller or how should I trigger this?? I need to send confirmation mail after each registration.. Thanks In advance

edited May '18

There are multiple options:

  1. Execute the command from PHP:
  2. Use a Queue technology, for example
  3. Cronjob that executes the file every given time.

Personally I use option 3. In my projects I have an email_queue table that holds the emails and a cronjob running every minute to send them.

CREATE TABLE `email_queue` (
  `id` int(11) UNSIGNED NOT NULL,
  `email` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `subject` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `template` varchar(63) COLLATE utf8_unicode_ci NOT NULL,
  `variables` text COLLATE utf8_unicode_ci NOT NULL COMMENT 'serialized key => value array',
  `priority` tinyint(1) NOT NULL COMMENT 'low 0 - 9 high',
  `created_at` datetime NOT NULL,
  `sent_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

So basically when a user registers, you insert a record in the DB and the cronjob does the work on the background.

edited May '18

Thank You sir @nikolay-mihaylov