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 http://your.dev.site/sandbox.php
To run the default store:
<?php
require 'app/Mage.php';
Mage::app();
// your code
To act as cron:
<?php
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
Posted by Mike Whitby to Magento (2012-04-11 10:07)