手册:runJobs.php

From mediawiki.org
This page is a translated version of the page Manual:RunJobs.php and the translation is 75% complete.
Outdated translations are marked like this.

Since MediaWiki 1.40, maintenance scripts should be invoked directly through maintenance/run.php . Invoking maintenance scripts directly will trigger a warning.

详情

runJobs.php文件是一个维护脚本,用于手动强制运行作业队列。 在正常情况下,队列中的作业作为用户与wiki交互的函数(普通的apache请求)运行。 运行作业的默认速率为1比1,可以通过调整LocalSettings.php 文件中的$wgJobRunRate 进行更改。 请注意,作业的默认内存限制为150 MB,这样坏作业不会占用服务器的所有内存。

您可能希望使用此脚本,因为wiki的流量太慢,无法清除队列,或者可能有大量作业需要清除。 但请注意,对于许多服务器配置,这可能会导致您的wiki在脚本完成之前变得迟钝甚至没有响应。 建议您先尝试50或100,以了解脚本的速度,然后再运行数百个作业或不带参数。

还请注意,如果意外运行了一个脚本,该脚本加载了大量不需要或不需要的作业,也可以通过清除wiki数据库中的job表来完全清除作业队列。 确保队列中没有您需要的作业,因为所有作业都将被无法恢复地删除。

用法

php maintenance/runJobs.php

高级用法

php runJobs.php [--conf|--dbpass|--dbuser|--globals|--help|--maxjobs|--maxtime|--memory-limit|--nothrottle|--procs|--quiet|--server|--type|--wait|--wiki]

通用维护参数

选项/参数 描述
无参数 将运行队列中当前的所有作业
--help (-h) 显示此帮助消息
--quiet (-q) 是否抑制非错误输出
--conf “LocalSettings.php”的位置,如果不是默认值
--wiki 用于指定wiki ID
--globals 在调试处理结束时输出全局变量
--memory-limit 为脚本设置一个特定的内存限制,“max”表示无限制,或“default”以避免更改它
--server 要在URL中使用的协议和服务器名称,例如https://en.wikipedia.org。这有时是必要的,因为在命令行脚本中服务器名称检测可能失败。

脚本相关的参数

选项/参数 描述
--dbuser 用于此脚本的数据库用户
--dbpass 用于此脚本的密码

脚本特定的参数

选项/参数 描述
--maxjobs 要运行的最大作业数
--maxtime 最长挂钟时间(秒)
--procs 要使用的进程数
--type 要运行的作业类型。 有关可用的工作类型,请参见$wgJobClasses
--wait 等待新作业而不是退出
--nothrottle 忽略作业限制配置
--result 设置为“json”以仅打印json响应

示例

php maintenance/runJobs.php --maxjobs 5  --memory-limit 150M --type refreshLinks
/home/flowerwiki/public_html/w/maintenance$ php runJobs.php --maxjobs 5 --memory-limit 150M --type refreshLinks

2010-10-29 13:50:38 refreshLinks Daisies t=501 good
2010-10-29 13:50:38 refreshLinks Magnolias t=501 good
2010-10-29 13:50:39 refreshLinks Heirloom_Roses t=500 good
2010-10-29 13:50:39 refreshLinks Carnations t=501 good
2010-10-29 13:50:40 refreshLinks Tulips t=563 good
不建议让"runJobs.php"无限期运行而没有任何限制($code1、$code2和/或$code3)。典型的用法包括定期运行,至少设置一个限制,以防止一次性运行时间过长。 Using --maxjobs on its own is insufficient, so it is best paired with --maxtime and/or --memory-limit. Typical usage involves periodic runs with at least one of the restrictions set to prevent it from running too long in one go.

Possible issues

The job queue appears to be stuck

Under certain circumstances, "runJobs.php" may hang indefinitely. Some jobs may fail to get completed, clogging up the queue.

理想情况下,您应该找到问题的原因,通常是从命令行运行的PHP的PHP.ini 中缺少PHP扩展。 Possible causes include

  • A missing PHP extension in the php.ini of the PHP being run from the command line.
  • A buggy extension.

No standard tools or methods are currently available to let you diagnose the issue.

Object caching

"runJobs.php" may hang if you have object caching enabled. If this happens, there is something you could try, with the caveat below in mind.

  1. Create another "LocalSettings.php" file with object caching disabled:
    $wgMainCacheType = CACHE_NONE;
    
  2. 然后使用--conf参数运行“runJobs.php”以指定禁用缓存的新LocalSettings.php文件的位置。

但是,不建议这样做,因为某些作业会从对象缓存中清除对象,因为缓存被禁用,所以不会清除对象。 这将导致某些更新不会反映在wiki上。

Terminate a running process

Sometimes, if you cannot find the problem and the job queue is creating overhead, you may have no other choice than to terminate it, possibly at the expense of deleting jobs you might need. If this is the case and you accept the risk, you can try to clear the job that you think is causing trouble, or clear the entire jobs table.

Note that on some control panels that use cronjob automation, clearing jobs may have no visible effect. The process initiated may still appear to hang even if there are no jobs left to execute.

Using a database administration tool
  • Go to your database administration tool (e.g. phpMyAdmin) and locate the job table.
  • If you're lucky, it may just be an active job that is causing trouble and that needs to be cleared. You can locate it by finding the row that has a hash value in the job_token column.
  • Repeat if necessary. If all else fails, clear the entire jobs table.
Using manageJobs.php

The maintenance script manageJobs.php does not lend you insights but it does let you delete jobs by group.

参见