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.

Meet cron

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.

Running a Magento 1.4 job through cron

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 

 

 

The main cronjob

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 

 

 

More Magento reindexing

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.

Clean logs and using the Magento compiler

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的变化和设置方法的不同之处

目录
相关文章
|
XML Java Android开发
Android Studio开发之使用内容组件Content获取通讯信息讲解及实战(附源码 包括添加手机联系人和发短信)
Android Studio开发之使用内容组件Content获取通讯信息讲解及实战(附源码 包括添加手机联系人和发短信)
698 0
|
11月前
|
前端开发 JavaScript
除了 jsPDF,还有哪些前端库可以用于生成 PDF?
【10月更文挑战第21天】这些前端库都有各自的特点和优势,你可以根据具体的项目需求、技术栈以及对功能的要求来选择合适的库。不同的库在使用方法、性能表现以及功能支持上可能会有所差异,需要根据实际情况进行评估和选择。
|
存储 IDE API
最佳实践:通过 FastAPI APIRouter 提升开发效率
FastAPI 是一个现代的、高性能的 Python Web 框架,它提供了 APIRouter 来帮助组织和管理路由。APIRouter 是一个可用于组织和分组路由的类,使得代码结构更加清晰和可维护。本文将介绍 FastAPI APIRouter 的用法,包括实践案例以及在 IDE 编辑器中的运行步骤。
|
SQL 运维 数据库
MSSQL性能调优实战:索引策略优化、SQL查询精细调整与并发管理
在Microsoft SQL Server(MSSQL)的运维与优化过程中,性能调优是确保数据库高效运行的关键环节
|
前端开发 Java 应用服务中间件
SpringBoot异步接口怎么实现?
### 前言 Servlet 3.0以前,每个HTTP请求由单一线程全程处理;3.0版本引入异步处理,允许提前释放容器线程,提升系统吞吐量。
288 0
|
API 项目管理 调度
OpenProject 是一个基于网络的项目管理软件。其主要特点是:
OpenProject 是一个基于网络的项目管理软件。其主要特点是:
395 1
|
算法 物联网 网络安全
HTTP/2:多路复用、服务器推送和首部压缩的革命
HTTP/2:多路复用、服务器推送和首部压缩的革命
HTTP/2:多路复用、服务器推送和首部压缩的革命
|
Prometheus 监控 前端开发
前端项目脚本加载失败:net:: ERR_HTTP2_PROTOCOL_ERROR 200
前端项目脚本加载失败:net:: ERR_HTTP2_PROTOCOL_ERROR 200
3409 0
前端项目脚本加载失败:net:: ERR_HTTP2_PROTOCOL_ERROR 200
|
开发工具
如何在 Vim 中剪切、复制和粘贴
如何在 Vim 中剪切、复制和粘贴
311 0
|
小程序 Java 程序员
基于java的坦克大战游戏的设计与实现--答辨PPT--【毕业论文】
基于java的坦克大战游戏的设计与实现--答辨PPT--【毕业论文】