The document discusses using the Zend framework in Magento to handle intensive data processing tasks more efficiently than using the Magento models directly. It provides an example of creating a shell script that initializes the database connection and tables using Zend functionality, then builds and executes a SQL query to retrieve product data in batches to avoid running out of memory. This allows intensive custom scripts to reuse clean, reusable code while avoiding overloading Magento for non-essential tasks.
Kenya Coconut Production Presentation by Dr. Lalith Perera
Utilization of zend an ultimate alternate for intense data processing
1. Utilization of Zend: An Ultimate Alternate For Intense Data
Processing
Magento development
Magento development company
Image source:
http://www.letsdiscussonline.com/wp-content/uploads/2016/12/Zend-Framework-Lets-Discus
s-Online.png
In Magento, sometimes there are cases where a lot of data processing needs to be complete
and using Magento models and resources is either too slow or too intensive for your solution.
When the Zend framework on which Magento is constructed upon jumps in. Normally, you can
write raw php/mysql functionality for your requirements, but if you wish to keep your code
clean and reusable, using Zend functionality is the way. Magento development company use
the Zend framework.
Solicitation like making feed generator or some other custom scripts that will be too substantial
if used with initializing Magento are quite often and can be accomplished by writing a shell
script (located in shell directory of Magento project root) which will be used only needed
resources to complete the task.
Let’s create the script backbone from Magento class Mage_Shell_Abstract that add Mage.php
needed for basic initialization project classes. Set up our class and its attributes needed for this
example. Create file called hello-example.php in our shell directory inside Magento project:
--------------------------------------------------------Code---------------------------------------------------------------
2. require_once 'abstract.php';
class Hello_Custom_Script extends Mage_Shell_Abstract
{
public $r = null;
public $c = null;
public $entityTypeId = null;
public $productTypeId = null;
public $tables = array();
public function _construct()
{
/** @var Mage_Core_Model_Resource r */
/** @var Varien_Db_Adapter_Interface c */
// Init connection and tables
$this->r = Mage::getSingleton('core/resource');
$this->c =
$this->r->getConnection(Mage_Core_Model_Resource::DEFAULT_WRITE_RESOURCE);
// Entity type for products
$this->entityTypeId = Mage::getModel('eav/config')
->getEntityType(Mage_Catalog_Model_Product::ENTITY)
->getEntityTypeId();
// Product type ID
$this->productTypeId = Mage_Catalog_Model_Product_Type::TYPE_SIMPLE;
// Table names
$this->tables['cpe'] = $this->r->getTableName('catalog_product_entity');
$this->tables['ea'] = $this->r->getTableName('eav_attribute');
$this->tables['cpev'] = $this->r->getTableName('catalog_product_entity_varchar');
$this->tables['cped'] = $this->r->getTableName('catalog_product_entity_decimal');
$this->tables['cpei'] = $this->r->getTableName('catalog_product_entity_int');
}
}
$script = new Hello_Custom_Script();
$script->run();
--------------------------------------------------------Code---------------------------------------------------------------
Call the function $this->c->select() initializes Varien_Db_Select.php which handles query build
with the help of Zend_Db_Select. Inside app/code/core/Zend/Db/Select.php you run out of
memory, also you can wrap up sql call in a while loop and call results one by one.
With this result in slower execution but will not waste as much memory
4. while($result = $values->fetch()) {
// Do something with data here
$return[] = $result;
}
return $return;
}
--------------------------------------------------------Code---------------------------------------------------------------
When everything is done you can call script from Magento root with php -f
shell/hello-example.php. Many Magento development company’s websites follow the Zend
framework.
Author bio:
Author -Harshal Shah
Website - http://www.elsner.com/
Address-305,306 Iscon Center,
Shivranjani Cross Road, Satellite,
Ahmedabad, India.
Phone number- +91 79 4006 2525