Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8163901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:10:32+00:00 2026-06-06T19:10:32+00:00

I started to use CakePHP (1.2) a few months ago to add small features

  • 0

I started to use CakePHP (1.2) a few months ago to add small features to the company’s application and I’m not too familiar with it.

We test locally then on a development server before merging to a production server.

I want a controller action to be called every hour with what I assumed to be the best way to do this through my researches, a cron job.


Attempt 1

After reading these,

http://bakery.cakephp.org/articles/mathew_attlee/2006/12/05/calling-controller-actions-from-cron-and-the-command-line

http://book.cakephp.org/1.2/en/view/110/Creating-Shells-Tasks

I could implement something without errors, but the action is not executed.

Based on these examples, I added a file named cron_dispatcher.php in my app directory (not app/webroot) and then did this command from the app dir

php cron_dispatcher.php /controller/action/param

Still nothing happened but it works perfect when I call it through the url.


Attempt 2

I tried creating a shell (email.php) that would call the action in /app/vendors/shells/.

<?php

class EmailShell extends Shell {

    public function main() {
        $this->out('Test');
    }

}
?> 

This successfully outputs Test in the console using

cake email main

but then I cannot find how to call the controller’s action. I have tried

$this->requestAction(‘/controller/action’);

I have also tried to make the call from a different function than the main in the shell.

I have tried to include the controller in the $uses variable as I would with a model but that didn’t work (and it doesn’t make sense I think)

I don’t think creating a task is the solution either as I don’t want to duplicate the sendEmails function hence why I’m looking for a way to just call the controller’s action from a shell or whatever!

There is probably some theory I’m missing, thanks


Solution

I moved some methods from the controller to a model and I was able to call them from a shell.

App::import('Component', 'Email');

class SendMemosShell extends Shell {

    var $uses = array(
        'Memo',
    );

    public function main() {

    }

    public function sendEmails () {
        $this->Email =& new EmailComponent(null);
        $memoList = $this->Memo->getMemos();
        //...
    }
}

This link helped
http://book.cakephp.org/2.0/en/console-and-shells/cron-jobs.html


edit : clarified some of the information and added the solution

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T19:10:35+00:00Added an answer on June 6, 2026 at 7:10 pm

    It is a quite common issue actually, ran into it also.

    A controller is deciding how to handle a request and starting that task. In this case there is no need for a controller since you have a shell task, the task is already clear.

    Knowing that, it does not make sense to call a controller method.

    So rethink your options, and yes this is a quite difficult one. For example you might decide that sending the e-mail is a business logic step so it should be in the model. Another option is to separate it totally (that’s what we like most).

    In that case you will have to create a queue where you put in all e-mails to send. That is a good design since you then know the amount of logic in the controller goes down and it is separated. That way you get an e-mail service.

    For example you could ask the service to send a “new user” mail. Then you add the User object to it and it should handle itself. That way you can even scale since your service could be for example outsourced, you could expand multiple servers on the service etc.

    Edit:

    Good questions.

    Steps to take:

    1. Centralize the “sending e-mail” process first. So choose one location where to put it. The you can decide: Add to send e-mail to a queue or call the service directly. For example you could add shell task for sending the e-mails.

    2. Call the shell: Now you have the problem to call the shell. In general you don’t want to. Why not? Because a shell (a task) could run for a long time. So that’s why we use queues in between. So you can ask the queue or let the queue message you that something is done. For example think about a mail server which is down. You have to retry etc. That should not be in a web request because the user is waiting for response.

    3. Third step is to call the shell from your cron, now that’s easy since you are already on the command line so you could use standard calls.

    Anyhow, there are options to do a direct call from a controller but you should not. This post gives some very interesting insights:
    CakePHP: Run shell job from controller

    Edit 31/08/’13: See the events system of CakePHP also for some examples: http://book.cakephp.org/2.0/en/core-libraries/events.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I started to use Borland's Turbo C++ a few days ago. I actually have
I started to use php a few hours ago. To begin studying I decided
I've started to use R a little while ago and am not sure how
I just started to use meioupload to upload my files from cakephp, however, i'm
We have an old (written in CakePHP 1.1!) application that has started groaning under
I run my own business from home and started use Python 2 days ago.
Started to use the add-migration command in the package manager console to generate the
I'm building my own C2DM application right now. I first started with a small
I've just started to use Partials in my rails application, at the moment i
Background: I'm new to CakePHP. I have a small test site (mostly composted of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.