天天看点

magento -- 1.4下的计划任务(cron job)

on some points, magento needs regular maintenance. for instance, when running a shop of which the products are updated frequently, it is needed to refresh catalog indices. also the search-index might need regular updating. to accomplish these tasks you can run magento cronjobs. with magentotm 1.4 this is even easier. here's how.

within linux environments, the program responsible for running scheduled tasks is called cron. tasks that are run through cron are referred to as cronjobs. by runnning cronjobs daily or perhaps weekly, you can automate certain processes like refreshing the magento indices or cleaning up logfiles.

running cronjobs is something that depends on your hosting environment. almost every linux-server is shipped with cron-functionality, but within shared hosting environments it just depends whether you are allowed to use or not. popular control panels like directadmin or cpanel often allow you to create new cronjobs.

with magento 1.3 and older, you had to write your own php-scripts to get things done. with magento 1.4 this has become much easier. within the magento directory "shell" you can find various php-scripts that automate certain actions. the rest of this tutorial will discuss those actions as well.

running such a script through cron doesn't mean calling this script through the browser. you'll need command-line access to your magento site to run such a script manually. in exactly the same way that you run this from the command-line, the cronjob is also run. in the following examples, you will need to replace "/path/to/magento" with the exact directory that contains magento.

php /path/to/magento/shell/indexer.php reindexall 

this will reindex all the magento indices. now this command first

calls the php-program "php" with as first argument the location of the

php-script, and as second argument something that is used as argument

for the script.

it might be that the "php" program is not found by cron, in which

case you will need to define the exact path to the "php" binary program:

/usr/local/bin/php /path/to/magento/shell/indexer.php reindexall 

to surpress output from the magento script you can also add the flag "-q" (quiet):

php -q /path/to/magento/shell/indexer.php reindexall 

if you're running against memory limits, you might try to skip the regular configuration by using the flag "-n":

php -n /path/to/magento/shell/indexer.php reindexall 

while this tutorial mainly deals with indexing and caching, there is

another cronjob which should be seen as the primary cronjob: it is

contained in the file "cron.php" and every magento module that wants to

schedule a certain job through magento is handled through it. the only

thing you need to do is run the script (without any arguments), let's

say every night:

/usr/local/bin/php /path/to/magento/cron.php 

when running the indexer.php script from the command-line we can find

more tricks. first of all we can check for the current status of all

the indices:

php /path/to/magento/shell/indexer.php --status 

we can also refresh a specific index. to do so, we first need to find out which arguments can be used:

php /path/to/magento/shell/indexer.php info 

this gives a listing like the following:

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 

now we found the technical names for the various indices, which we can use like the following example:

php /path/to/magento/shell/indexer.php --reindex catalog_product_flat 

the last example is again something we can use through cron.

besides refreshing indices, we can also clean up all the logs within the database:

php /path/to/magento/shell/log.php clean 

even cooler is the new magento compiler module which is still in beta

but gives great performance benefit by reducing the number of

include-paths (4 by default) to one single include-path. this mainly

saves cpu-resources.

you can check for the current state of the compiler by running the following:

php /path/to/magento/shell/compiler.php state 

once checked you can disable the compiler temporarily, rebuild the

include-paths again with the flag "compile" and enable the compiler once

more.

php /path/to/magento/shell/compiler.php disable

php /path/to/magento/shell/compiler.php compile

php /path/to/magento/shell/compiler.php enable 

原文链接地址:http://www.yireo.com/tutorials/magento/magento-administration/340-magento-14-cronjobs

ps:   关于cronjobs我已经在置顶的文章里描述过,内容是基于magento1.3的       http://blog.csdn.net/shuishui8310/archive/2010/05/08/5570926.aspx

        这篇文章描述的是magento1.4环境下cronjobs的变化和设置方法的不同之处