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

  • SEARCH
  • Home
  • 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 9133417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:29:06+00:00 2026-06-17T08:29:06+00:00

I have a cron task in Magento that I need to profile to determine

  • 0

I have a cron task in Magento that I need to profile to determine memory usage problems. The script runs during the night, and crashes after half an hour or so due to consuming all available memory.

I need to profile the script to determine which functions are consuming too much memory.

I have tried using the Aoe_Profiler, but when trying to profile a cron task, there is nowhere to view the output, as the cron task does not invoke the MVC, thus the profiler’s view block can’t be rendered.

How can a cron task be profiled in Magento?

  • 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-17T08:29:07+00:00Added an answer on June 17, 2026 at 8:29 am

    A ‘trick’ we have used from time to time in running and debugging/testing cron scripts from the command line is to copy cron.php that lives in the root folder of the Magento application to a new script that represents the cron task that you wish to execute, eg xyz_cron_task.php.

    Down the bottom of that script is a try/catch block:

    try {
        Mage::getConfig()->init()->loadEventObservers('crontab');
        Mage::app()->addEventArea('crontab');
        Mage::dispatchEvent('default');
    } catch (Exception $e) {
        Mage::printException($e);
    }
    

    This can be changed as follows, to run just the cron task you’re interested in:

    try {
        Mage::getModel('your_module/cron')->yourCronTask();
    } catch (Exception $e) {
        Mage::printException($e);
    }
    

    Now the cron task can be executed from the command line, or the browser. You can visit the page http://yourdomain/xyz_cron_task.php, and the cron task will be executed (although you won’t see anything interesting yet).

    To get the profiling working (assuming you have already enabled profiling in the Admin section), add the following code after require 'app/Mage.php';:

    Varien_Profiler::enable(); // This enables profiling
    Mage::setIsDeveloperMode(true); // This allows you to see exceptions etc, but not stricly required.
    

    This will enable profiling, but you still won’t see the profiler output, as there is no view model to render it.

    You can output the profiler block by adding one line to the try/catch block as follows:

    try {
        Mage::getModel('harmony/cron')->importProductsAndStock();
    
        // The following line outputs the profiler block.
        echo Mage::app()->getLayout()->createBlock("core/profiler")->toHtml();
    } catch (Exception $e) {
        Mage::printException($e);
    }
    

    You should now see the profiler output as follows (assuming you’re using the Aoe_Profiler extension):

    enter image description here

    Now you can the appropriate Varien_Profiler::start()/stop() code to your cron task as required.

    Happy profiling!

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

Sidebar

Related Questions

I have a cron entry that runs a script at a certain time each
I have a shell script ( /home/user/send_report.sh ) that runs my rake task: cd
I have a cron task that runs once a day, using Heroku's Daily Cron
I have a cron job to run a Ruby script, which runs fine on
I have a CRON job php script that I just set up not too
I need to write a shell script to run as a cron task, or
I have a cron task that logs a value in my database every 15
I have a cron that for the time being runs once every 20 minutes,
I'm writing script that build apps with cron task, I can build any app
I have an update query being run by a cron task that's timing out.

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.