Let's see how does it work through a little exemple. The follwing exemple is quite stupid, but it's just to show the way you can create a task. So the aim of this task is to display a sentence given as an arguments for each user from your data base.
Basically you will have to create a class which extend from sfBaseTask and use the configure() method to set the name, the name space, the options and the arguments of your task. Then you will have to implement an execute() function to handle your data.

// myProject/lib/task/SayHelloTask.class.php

class SayHelloTask extends sfBaseTask
{
    const ALL_USERS = -1;

    public function configure()
    {
        // task's name, description and aliases
        $this->name = "say-hello";
        $this->namespace = "mytasks";
        $this->briefDescription = "A little description of this task.";
        $this->detailedDescription = "Detailed description, blablablabla blabla blabla bla.";
        $this->aliases = array('mytasks-say-hello', 'sh');

        // options
        $this->addOptions(array(new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environement', 'prod')));

        // arguments
        $this->addArguments(array(new sfCommandArgument('message', sfCommandArgument::OPTIONAL, 'your message', 'Hello %s :)'),
                                  new sfCommandArgument('number', sfCommandArgument::OPTIONAL, 'how many users ?', self::ALL_USERS)));
    }

    public function execute($arguments = array(), $options = array())
    {
        // data base manager to open a connection
        $sfDatabaseManager = new sfDatabaseManager($this->configuration);

        if(substr_count($arguments['message'], '%s') === 1)
        {
            // get users from data base
            $users = UserTable::getAll();

            $end = 0;
			$nbUsers = count($users);
			if($arguments['number'] === self::ALL_USERS)
			{
				$end = $nbUsers;
			}
			else
			{
                $nb = (int) $arguments['number'];
                $end = ($nb <= $nbUsers) ? $nb : $nbUsers;
			}

			$i = 0;
			while($i<$end)
			{
                $this->log(sprintf($arguments['message'], $users[$i]->getFullName()));
                $i++;
		    }
		}
		else
		{
			$this->logBlock("Only one '%s' in the message.", 'ERROR');
		}
    }
}

To run this task you just have to execute this command line :

$ php symfony mytasks:say-hello

OR

$ php symfony mytasks:say-hello "Hi %s :p"

OR

$ php symfony sh "Hi %s :p"