Posted almost 10 years ago. Visible to the public.

Sandbox Script

Sometimes you want to run some code to see what it does, dump an object out or check a class but the thing you want to run/dump/check is hidden deep in the bowels of the code somewhere, and you feel it might be easier to run a bit of PHP to check just that one thing, without having to fire up or your browser, or wait for cron to run - that's where this sandbox script comes in.

To use either of the examples below, save them into a file in the root of your magento install called sandbox.php, then either browse to the directory and run php -f sandbox.php or visit

To run the default store:
require 'app/Mage.php';

Mage::app(); // your code

To act as cron:
require 'app/Mage.php';

$_SERVER['SCRIPT_NAME'] = str_replace(basename(__FILE__), 'index.php', $_SERVER['SCRIPT_NAME']); $_SERVER['SCRIPT_FILENAME'] = str_replace(basename(__FILE__), 'index.php', $_SERVER['SCRIPT_FILENAME']); Mage::app('admin')->setUseSessionInUrl(false); Mage::getConfig()->init()->loadEventObservers('crontab'); Mage::app()->addEventArea('crontab'); // your code

Owner of this card:

Mike Whitby
Last edit:
about 8 years ago
Posted by Mike Whitby to Magento
This website uses short-lived cookies to improve usability.
Accept or learn more