shell命令刷新indexer

转子:http://www.propellermind.com/magento-tips/magento-re-index-data-with-command-shell/

Magento uses a lot of resources to re-index data from the Admin Panel. A good way to re-index data without using the admin panel is to use command shell “ssh”. This also would work if you happen to be locked out of the admin panel.

Here is instruction on how to use default Magento indexer via SSH:

1 – Go to ‘shell’ folder in your Magento installation:

cd shell

2 – Execute reindex using this command:

php -f indexer.php reindexall

It is possible to get full list of Magento indexer commands using this command:

php -f indexer.php help

To get a list of available indexes, execute this command:

php -f indexer.php info

By default there are 8 indexes in Magento:

catalog_product_attribute     Product Attributes
catalog_product_price         Product Prices
catalog_url                   Catalog Url Rewrites
catalog_product_flat          Product Flat Data
catalog_category_flat         Category Flat Data
catalog_category_product      Category Products
catalogsearch_fulltext        Catalog Search Index
cataloginventory_stock        Stock status

Individual commands for re-indexing:

php indexer.php --reindex catalog_product_attribute
php indexer.php --reindex catalog_product_price
php indexer.php --reindex catalog_url
php indexer.php --reindex catalog_product_flat
php indexer.php --reindex catalog_category_flat
php indexer.php --reindex catalog_category_product
php indexer.php --reindex catalogsearch_fulltext
php indexer.php --reindex cataloginventory_stock
php indexer.php --reindex tag_summary

二:

In some situation when you want to re-index Magento catalog you will get an error message or reindex process will be broken. This problem is appearing when you have a lot of products in database and limited server resource. You can try to reindex from command line or shell.
In Magento there is folder with name “shell” in this folder you will find file with name “indexer.php” this is shell script for reindexing. You will ask yourself how to call this script, and take a look on my examples below and everything will be clear.

First of all you need to have access to linux commnad line or shell, and then go to your “MAGENTO_ROOT_FOLDER/shell“.


-jailshell-3.2$ pwd
/home/mcomerce
-jailshell-3.2$ ls
access-logs            etc   perl5    public_ftp   ssl  www
cpbackup-exclude.conf  mail  php.ini  public_html  tmp
-jailshell-3.2$ cd public_html/
-jailshell-3.2$ cd shell/
-jailshell-3.2$ ls
abstract.php  compiler.php  indexer.php  log.php
-jailshell-3.2$
Our first example is how to get help from “indexer.php” script, you need to execute next comand
php -f indexer.php help ” and you will get response as in example below.

$ php -f indexer.php help
  --status <indexer>            Show 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                          This help
  <indexer>     Comma separated indexer codes or value "all" for all indexers

You can see that you can make reindexall but I don’t recommend that you execute full reindex in one step, beacuse you can cause MySql/Server overload. Reindexall calls 8 indexers in a row and process of reindexing can cause database LOCK on some database tables.

I recommend that you execute one by one indexer. You process will be faster and load of database will be smaller.

In Magento there are 8 indexers, you can get list of indexers if you call next command:
php -f indexer.php info

-jailshell-3.2$ php -f indexer.php info
catalog_product_attribute     Product Attributes
catalog_product_price         Product Prices
catalog_url                   Catalog Url Rewrites
catalog_product_flat          Product Flat Data
catalog_category_flat         Category Flat Data
catalog_category_product      Category Products
catalogsearch_fulltext        Catalog Search Index
cataloginventory_stock        Stock status
-jailshell-3.2$

For example if you want to reindex “ catalog_url ” you need to execute next command:
php -f indexer.php — -reindex catalog_url , below is example

-jailshell-3.2$ php -f indexer.php -- -reindex catalog_url
Catalog URL Rewrites index was rebuilt successfully
-jailshell-3.2$

I recommend that you use indexer from shell because this process isn’t executing over web server/Apache and makes smaller impact on server resources :-).

One note: I had problem with php memory limit, error message: “Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 88 bytes)“. I increased memory size to 128Mb, I added next statement on beginning of script:ini_set(‘memory_limit’, ’128M’); .
That’s all for now ;-)
















评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值