Deprecated: Assigning the return value of new by reference is deprecated in /home/bigfish/blogs/adam/wp-includes/cache.php on line 36

Deprecated: Assigning the return value of new by reference is deprecated in /home/bigfish/blogs/adam/wp-includes/query.php on line 21

Deprecated: Assigning the return value of new by reference is deprecated in /home/bigfish/blogs/adam/wp-includes/theme.php on line 540
New CakePHP “multitask” Plugin : Adam Royle

New CakePHP “multitask” Plugin

What is multitask?

Multitask is a CakePHP plugin designed as a proof of concept task manager for non-interactive tasks.

It consists of:

  1. MultitaskerShell - a daemon that manages the tasks/threads
  2. MultitaskQueuedTask - a model for adding queued tasks
  3. ThreadedTask - a base class for your tasks

What does it do?

The multitasker shell acts as a daemon, getting a task from a model, executing it, and updating its status when done.

It could be used for executing long-running tasks in the background, such as tasks involving significant network activity or encoding video, etc.

Installation & Usage

  1. Copy the "multitask" folder into the plugins folder of your CakePHP app.
  2. Import the database schema from config/multitask.sql
  3. Run "multitasker" shell from the command line.

cd cake/console/
./cake multitasker -app ../../app

Then add some tasks into your database and it will execute them. :)

Here is some code that will add a task into the queue. Look in vendors/shells/tasks/echo.php for the task being executed.

$this->MultitaskQueuedTask = ClassRegistry::init('Multitask.MultitaskQueuedTask');

$task = array(
    'task' => 'echo',
    'data' => 'Hello, World!',
);

$this->MultitaskQueuedTask->create($task, true);
$this->MultitaskQueuedTask->save();


$task = array(
    'task' => 'echo',
    'method' => 'delayed',
    'data' => array('duration' => 3, 'message' => 'That was a nice sleep!'),
);

$this->MultitaskQueuedTask->create($task, true);
$this->MultitaskQueuedTask->save();

Known Issues

I've not used this in production and don't recommend you do either! Heck, I haven't used it aside from a few small tests, so use with caution.

The plugin is in its elementary stages, and doesn't handle scripting errors, task progress, task dependencies, task priorities, etc.

Requirements

PHP needs to be configured with pcntl and shmop extensions, as it uses PHP_Fork to handle threading.

I have only tested it on PHP5. Please let me know if you get it working on PHP4.

Windows Compatibility

Although the pcntl and shmop extensions don't run on Windows, I have added "linear threading" (ie. no threading) so you can test the functionality of your tasks on Windows.

Where can I get it?

UPDATE: I've now pushed it to github - http://github.com/ifunk/Multitask for easy downloading...

Comments

20 Responses to “New CakePHP “multitask” Plugin”

  1. Adrian on April 1st, 2009 12:54 pm

    Thanks a lot!
    Some questions if I can:
    When I run multitasker appers two process with "ps axwww | grep cake.php", thats ok?
    Then when I add tasks the processes multiplies by two... and only died with CTRL-C in multitasker
    Can I not run multitasker, I meen, run once cron by hour an run the scheduled tasks?
    Thanks again!
    PD: Sorry for my english

  2. Adam on April 1st, 2009 1:09 pm

    @Adrian: Although theoretically you could schedule it to run once at hour on cron, it was originally designed to work as a daemon that is executed upon startup, and keeps running continuously in the background.

    It would be fairly straightforward to change the behaviour so it exits immediately after it completes all of its tasks, just change sleep(1); to exit; in the MultitaskerShell.

    I personally haven't experienced the multiplying processes you mentioned, but it's been a little while since I played with this so anythings possible. If you seriously want to use the shell, let me know and I will look into it further.

  3. Adrian (Hardian) on April 3rd, 2009 1:54 pm

    @Adam: Thanks for all!
    I'm using your plugin to process uploaded files.
    Forget about duplicate processes, I have to reserach about it.
    I add tickets in the chaw.
    Thanks again!

  4. Anonymous on November 27th, 2009 9:48 am

    Can I have a download link?

  5. Adam on November 27th, 2009 10:10 am

    @Anonymous: I've pushed it now to github - check the URL in the post.

  6. merovinq on May 8th, 2010 1:18 am

    Nice plugin, this is exactly what I was looking for. Kudos to you sir!

  7. Web designing companies bangalore on October 4th, 2012 5:55 pm

    I just read through the entire article of yours and it was quite good. This is a great article thanks for sharing this informative information. I will visit your blog regularly for some latest post.

  8. Lehenga sarees on October 10th, 2013 2:59 pm

    hello!, I love the writing so much! percentage many of us be in contact extra approximately the post in AOL? We need a specialist in this house to resolve my issue. May be that is people! Taking a look forward to see people.

  9. Houlteninstitute.com on January 10th, 2014 1:21 pm

    I recently go through over the write-up connected with your own property plus it ended up being rather excellent. This is a fantastic write-up thank you intended for revealing this particular beneficial info. I am going to stop by your site regularly for a few most recent publish.

  10. Tension Springs on January 13th, 2014 10:20 pm

    I thought it was going to be some boring old post, but it really compensated for my time. I will post a link to this page on my blog. I am sure my visitors will locate that extremely useful.

  11. Hotel Duvets on January 19th, 2014 11:39 pm

    A large thanks to Rita and all the employees and residents for allowing us use their wonderful irrigating hole!Hotel Duvets

  12. online accounting software on February 5th, 2014 3:10 am

    Good information allocated here. Thanks for talking about this information. I was looking for this information and finally i did get it from here.

  13. online accounting software on March 16th, 2014 12:46 am

    The weblog was definitely fantastic! Lot of excellent details which can be eye-catching some or the other way. Keep helping the weblog, anticipating for more contents

  14. garcinia cambogia whole body on April 24th, 2014 1:51 pm

    Hats off for publishing this unique comments here, would be used always for best outcomes more often, the results would be positive always

  15. Cambogia 75% on April 26th, 2014 9:07 pm

    This is a great article thanks for sharing this informative information. I will visit your blog regularly for some latest post.Cambogia 75%

Leave a Reply