We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Event after Task in Console Application

How do add an event to run after running a console task? I'm basically trying to add a debug event after running the console task to print out queries, time taken, etc.



98.9k

You can attach an events manager to cli/console:

<?php

$em = new Phalcon\Events\Manager();

$em->attach("console:afterHandleTask", function($event, $console) {
    //Executed after handle the task
});

$console = new Phalcon\CLI\Console();
$console->setEventsManager($em);

$console->handle(...);


6.1k

thanks, worked perfectly!