Cron jobs in Zend Framework

Recently i had to implement a cronjob for a website that was build with zend framework, and to be honest i haven’t done this before. I did some googling and as a lot of times with zend framework there arent to many resources about this topic.

I did find some topics on about it ( found out about zend cli proposal wich sounds interesting ) but not really an answer. So i decided to go ahead and try a solution on my own.

I wrote a while ago about my implementation of the bootstrap file and although that doesn’t look to impressive that helped me to build an easy init for the backup files.

So first of all i must tell you that i added a folder in my root folder ( same level with library ) called crons.
In it i added a file called init.php in witch i “start” the zend machine. I only call some methods from the bootstrap class since you don’t really need all the zend machine.


  1. $time = microtime(true);
  2. $memory = memory_get_usage();
  3. require ‘../application/bootstrap.php’;
  4. Bootstrap::setupEnvironment();
  5. Bootstrap::setupRegistry();
  6. Bootstrap::setupConfiguration();
  7. Bootstrap::setupDatabase();
  8. Bootstrap::setupTranslation();
  9. register_shutdown_function(‘__shutdown’);
  10. function __shutdown() {
  11. global $time, $memory;
  12. $endTime = microtime(true);
  13. $endMemory = memory_get_usage();
  14. echo
  15. Time [‘ . ($endTime – $time) . ‘] Memory [‘ . number_format(( $endMemory – $memory) / 1024) . ‘Kb]’;
  16. }

As you see i added some extra lines to do some little debugging of the cronjobs.

To add a cronjob you place a file in the crons folder you just created and you just include the init file and then you are on your way to code the cron functionality.




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s