This website uses cookies

Our website, platform and/or any sub domains use cookies to understand how you use our services, and to improve both your experience and our marketing relevance.

✨ Vultr and Linode are back on Cloudways! VIEW PLANS→

A Look On Basic PHP Shell Scripts For Magento

Updated on December 24, 2021

3 Min Read

Most of you already know that by default Magento has a few shell scripts available in {MAGENTO/shell/} we can use from command line. If someone tries to perform the script function from the frontend, it can cause a timeout and create issues in the server resources. Therefore, it is highly recommended that it should be used from CLI which can increase productivity and can save time. Furthermore, we can also schedule php shell scripts via CRON which can save a lot of time.

Php Shell Scripts

Next, I will be talking about Shell directory. Every file available under shell directory has its own function which is explained below:


Abstract.php contains Mage_Shell_Abstract class, which is used by other shell scripts available in shell directory. Custom shell scripts can be created by using few methods that are available in this file; methods like parseArgs(), _applyPhpVariables(), etc. This is mainly for advanced users. You can skip this and move to other shell scripts.


Magento Compilation was introduced in Magento Community Edition 1.4.2. This feature combines class files that are scattered in app/code/local/, app/code/community/, app/code/core/, and lib/ into a single location in /includes/src/. (The include directory must be writable to make this work.)

Compilation can reduce lookup time of these classes as all of them will be available in the single location. Installation, upgradation, and removal of any plugin require this feature to be disabled. Compilation can be disabled from admin, but if you want to disable it from CLI (or you forgot to disable it before installing the extension and you are unable to access admin panel), then given below is the usage of compiler.php:

@> php compiler.php --help
Usage: php -f compiler.php -- [options]
state Shows Compilation State
compile Runs Compilation Process
clear Disables Compiler include path and removes compiled files
enable Enables Compiler include path
disable Disables Compiler include path
help Provides help
Example usage: php compiler.php --disable


Magento indexes the products data in separate database tables to provide fast access on request, but this requires re-indexing if any changes are made in products, prices, etc. This is done to ensure that the changes are reflected on the frontend. This helps in performance when you have a large number of products, but it can cause issues with server resources and timeouts when re-indexing from admin. Indexer.php can help re-indexing all the indexers from CLI. We can also set CRON of indexer.php and can execute it on daily, weekly, or monthly basis. Below is the usage of indexer.php:

@> php indexer.php help

Usage: php -f indexer.php -- [options]
--status <indexer> Shows Indexer(s) status
--mode <indexer> Show Indexer(s) index mode
--mode-realtime <indexer> Set index mode type “Update on Save”
--mode-manual <indexer> Set index mode type “Manual Update”
--reindex <indexer> Reindex data
info Show allowed indexers
reindexall Reindex data by all indexers
help Provides help
<indexer> Comma separated indexer codes or value “all” for all indexers
Example usage: php indexer.php reindexall

With large database, it is not recommended to re-index all indexers at the same time. Individual indexers can be identified with following command.

@> php indexer.php info
catalog_product_attribute Product Attributes
catalog_product_price Product Prices
catalog_url Catalog URL Rewrites
catalog_category_product Category Products
catalogsearch_fulltext Catalog Search Index
cataloginventory_stock Stock Status
tag_summary Tag Aggregation Data

After identifying indexers, you can trigger indexing on them with following command:

@> php indexer.php --reindex catalog_product_attribute


Magento maintains logs of visitors, URL, etc., in its database. Following tables are used for maintaining logs:


The size of these tables increases as the time passes by. Therefore, these tables require cleaning from time to time. Log cleaning can be scheduled from admin, but we can use CLI mode to manually clean log tables or for scheduling via CRON. Below is the usage of log.php:

Usage: php -f log.php -- [options]
php -f log.php -- clean --days 1
clean Cleans logs
--days <days> Saves logs, days. (Minimum 1 day, if defined – ignoring system value)
status Displays statistics per log tables
help Provides help
Example usage: php log.php -- clean
If you want to retain a 3-day log:
Example usage: php log.php -- clean --days 3

Well, that’s about it. I hope I have added to your knowledge and hope that this post helped you in completing your tasks in a more efficient and effective manner, especially when it comes to Magento compilation, indexing, and log cleaning.

If you have any feedback or suggestions about php shell script, then do let me know by using the comments section below.

Get super fast Magento cloud servers on Cloudways

The beauty of Cloudways Click&Go platform is that it allows you the convenience of doing almost everything with your Magento environment. Using SSH terminal, you can run these scripts on your Magento cloud server. If you are not using Click&Go platform, start a free trial from the banner given below and check out everything that we have to offer.

Share your opinion in the comment section. COMMENT NOW

Share This Article

Abdur Rahman

Abdur Rahman is the Magento whizz at Cloudways. He is growth ambitious, and aims to learn & share information about Ecommerce & Magento Development through practice and experimentation. He loves to travel and explore new ideas whenever he finds time. Get in touch with him at [email protected]


Get Our Newsletter
Be the first to get the latest updates and tutorials.

Thankyou for Subscribing Us!


Webinar: How to Get 100% Scores on Core Web Vitals

Join Joe Williams & Aleksandar Savkovic on 29th of March, 2021.

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

Want to Experience the Cloudways Platform in Its Full Glory?

Take a FREE guided tour of Cloudways and see for yourself how easily you can manage your server & apps on the leading cloud-hosting platform.

Start my tour


  • 0


  • 0


  • 0


  • 0



For 4 Months &
40 Free Migrations

For 4 Months &
40 Free Migrations

Upgrade Now