Calling plugin controller externally fails with 500 error UPDATE: Question edited to be clearer.

I had an issue where it seems calling a plugin’s controller via an URL caused the site itself to throw a 500 error (i.e. not being accessible at all).

The plugin loads external cinema events (as an XML) and creates entries for films and shows. I’ve made it accessible in the CP, where I hit a button to update, and it will return a log which gets printed out in the CP. Triggering it from the plugins page in the CP works perfectly. Now I wanted to create a cronjob that loads the external data on regular intervals – basically calling the plugin. After some trail and error, I managed to make the plugin’s controller callable from the outside.

So my question is – is there anything special to be aware of when calling plugins from the outside? Is there a difference if it’s called as a cronjob or if it’s done manually through the browser.

Here is the code of the controller:

&lt;?php
namespace Craft;

class UpdateProgram_ProgramController extends BaseController
{
  // Allowing to be called without being logged in
  protected $allowAnonymous = true;

  public function actionUpdate()
  {
  // Disabling having to call the plugin by POST, to access directly by URL
  // this-&gt;requirePostRequest();

    $log = craft()-&gt;updateProgram_program-&gt;update();

    // If there are entries in the log, changes have happened
    if ( count($log) ) {
        craft()-&gt;userSession-&gt;setNotice(Craft::t('Program updated.'));
        craft()-&gt;urlManager-&gt;setRouteVariables(array(
           'log' =&gt; $log
        ));
    }
    // Otherwise, give an error message
    else {
        craft()-&gt;userSession-&gt;setNotice(Craft::t('Nothing to update!'));
    }
  }
}


And this is how I'm calling it from the cronjob:

MAILTO=[my.email@address]
# Run updateProgram every night at 3am
0 3 * * * wget http://[my.site]/actions/updateProgram/program/update &gt; /dev/null


When trying it from the browser, I used the same URL
So my question is – is there anything special to be aware of when calling plugins from the outside? 


Not particularly.  They're both hitting the same controller endpoint in your plugin, but there are about a million flags/options you can pass into wget to change it's runtime behaviors you might want to play with.

Personally, I stick with using cURL for cronjobs.

Regardless, the behavior you describe sounds like a webserver/Apache crash or segfault.  If they are long-running scripts and you inadvertently triggered them multiple times, maybe you hit some hard resource limits. If that's the case, the underlying error message would be in your web server's error logs for the 500 Internal Server Error.

If it were Craft generated 500 ISEs, then the underlying error message would be in craft/storage/runtime/logs.