<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://mediawiki.numinix.com/index.php?action=history&amp;feed=atom&amp;title=Manual%2FJob_queue</id>
	<title>Manual/Job queue - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://mediawiki.numinix.com/index.php?action=history&amp;feed=atom&amp;title=Manual%2FJob_queue"/>
	<link rel="alternate" type="text/html" href="https://mediawiki.numinix.com/index.php?title=Manual/Job_queue&amp;action=history"/>
	<updated>2026-07-25T22:52:29Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.1</generator>
	<entry>
		<id>https://mediawiki.numinix.com/index.php?title=Manual/Job_queue&amp;diff=18&amp;oldid=prev</id>
		<title>Admin: Seed from mediawiki.org for Seekmodo connector demo</title>
		<link rel="alternate" type="text/html" href="https://mediawiki.numinix.com/index.php?title=Manual/Job_queue&amp;diff=18&amp;oldid=prev"/>
		<updated>2026-07-25T17:02:12Z</updated>

		<summary type="html">&lt;p&gt;Seed from mediawiki.org for Seekmodo connector demo&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;languages/&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:2--&amp;gt; The &amp;#039;&amp;#039;&amp;#039;job queue&amp;#039;&amp;#039;&amp;#039; is designed to hold many short tasks using [[w:batch processing|batch processing]].&amp;lt;/translate&amp;gt;&lt;br /&gt;
It is commonly used to perform long-running tasks asynchronously, although a synchronous mode is available, too.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
== Set up == &amp;lt;!--T:3--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:122--&amp;gt; It is recommended that you schedule the running of jobs completely in the background, via the command line.&amp;lt;/translate&amp;gt;&lt;br /&gt;
If you do not have access to the command line but your hosting plan comes with a web control panel, it may well include a cronjob scheduler.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:4--&amp;gt; By default, jobs are run at the end of a web request. Disable this default behaviour by setting &amp;lt;tvar name=1&amp;gt;&amp;lt;/tvar&amp;gt; to &amp;lt;tvar name=2&amp;gt;&amp;lt;code&amp;gt;0&amp;lt;/code&amp;gt;&amp;lt;/tvar&amp;gt;.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{note|1=&amp;lt;translate&amp;gt;&amp;lt;!--T:99--&amp;gt; You should run &amp;lt;tvar name=1&amp;gt;&amp;lt;code&amp;gt;runJobs.php&amp;lt;/code&amp;gt;&amp;lt;/tvar&amp;gt; as the same user as the web server runs as, to ensure that permissions to the filesystem are correctly accounted for if jobs touch uploaded files.&amp;lt;/translate&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
=== Cron === &amp;lt;!--T:119--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:5--&amp;gt;&lt;br /&gt;
You could use [[w:Cron|cron]] to run the jobs every hour. For instance, add the following to your crontab file:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
0 * * * * /usr/bin/php /var/www/wiki/maintenance/runJobs.php --maxtime=3600 &amp;gt; /var/log/runJobs.log 2&amp;gt;&amp;amp;1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:120--&amp;gt;&lt;br /&gt;
Using Cron makes it easy to get started, but can make email notifications and cascading template feel slow (to wait up to an hour). Consider using one of the below approaches to set up a continuous job runner instead.&lt;br /&gt;
&lt;br /&gt;
=== Continuous service === &amp;lt;!--T:100--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:101--&amp;gt;&lt;br /&gt;
If you have shell access and the possibility to create init scripts, you can create a simple service to run jobs as they become available, and also throttle them to prevent the job runner from monopolising the CPU resources of the server:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:102--&amp;gt;&lt;br /&gt;
Create a bash script, for example at &amp;lt;tvar name=1&amp;gt;&amp;lt;code&amp;gt;/usr/local/bin/mwjobrunner&amp;lt;/code&amp;gt;&amp;lt;/tvar&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
==== Create script ==== &amp;lt;!--T:133--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# &amp;lt;translate nowrap&amp;gt;&amp;lt;!--T:103--&amp;gt; Put the MediaWiki installation path on the line below&amp;lt;/translate&amp;gt;&lt;br /&gt;
MW_INSTALL_PATH=&amp;quot;/home/www/www.mywikisite.example/mediawiki&amp;quot;&lt;br /&gt;
RUN_JOBS=&amp;quot;$MW_INSTALL_PATH/maintenance/runJobs.php --maxtime=3600&amp;quot;&lt;br /&gt;
echo &amp;lt;translate nowrap&amp;gt;&amp;lt;!--T:104--&amp;gt; Starting job service...&amp;lt;/translate&amp;gt;&lt;br /&gt;
# &amp;lt;translate nowrap&amp;gt;&amp;lt;!--T:105--&amp;gt; Wait a minute after the server starts up to give other processes time to get started&amp;lt;/translate&amp;gt;&lt;br /&gt;
sleep 60&lt;br /&gt;
echo &amp;lt;translate nowrap&amp;gt;&amp;lt;!--T:106--&amp;gt; Started.&amp;lt;/translate&amp;gt;&lt;br /&gt;
while true; do&lt;br /&gt;
	# &amp;lt;translate nowrap&amp;gt;&amp;lt;!--T:107--&amp;gt; Job types that need to be run ASAP no matter how many of them are in the queue&amp;lt;/translate&amp;gt;&lt;br /&gt;
	# &amp;lt;translate nowrap&amp;gt;&amp;lt;!--T:108--&amp;gt; Those jobs should be very &amp;quot;cheap&amp;quot; to run&amp;lt;/translate&amp;gt;&lt;br /&gt;
	php $RUN_JOBS --type=&amp;quot;enotifNotify&amp;quot;&lt;br /&gt;
	# &amp;lt;translate nowrap&amp;gt;&amp;lt;!--T:109--&amp;gt; Everything else, limit the number of jobs on each batch&amp;lt;/translate&amp;gt;&lt;br /&gt;
	# &amp;lt;translate nowrap&amp;gt;&amp;lt;!--T:110--&amp;gt; The &amp;lt;tvar name=1&amp;gt;--wait&amp;lt;/tvar&amp;gt; parameter will pause the execution here until new jobs are added, to avoid running the loop without anything to do&amp;lt;/translate&amp;gt;&lt;br /&gt;
	php $RUN_JOBS --wait --maxjobs=20&lt;br /&gt;
	# &amp;lt;translate nowrap&amp;gt;&amp;lt;!--T:112--&amp;gt; Wait some seconds to let the CPU do other things, like handling web requests, etc&amp;lt;/translate&amp;gt;&lt;br /&gt;
	echo &amp;lt;translate nowrap&amp;gt;&amp;lt;!--T:113--&amp;gt; Waiting for 10 seconds...&amp;lt;/translate&amp;gt;&lt;br /&gt;
	sleep 10&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:114--&amp;gt;&lt;br /&gt;
Depending on how fast the server is and the load it handles, you can adapt the number of jobs to run on each cycle and the number of seconds to wait on each cycle.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:115--&amp;gt;&lt;br /&gt;
Make the script executable (&amp;lt;tvar name=1&amp;gt;&amp;lt;code&amp;gt;chmod 755&amp;lt;/code&amp;gt;&amp;lt;/tvar&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
==== Create service ==== &amp;lt;!--T:134--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:116--&amp;gt; If using systemd, create a new service unit by creating the file &amp;lt;tvar name=1&amp;gt;&amp;lt;code&amp;gt;/etc/systemd/system/mw-jobqueue.service&amp;lt;/code&amp;gt;&amp;lt;/tvar&amp;gt;.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:117--&amp;gt; Change the &amp;lt;tvar name=1&amp;gt;&amp;lt;code&amp;gt;User&amp;lt;/code&amp;gt;&amp;lt;/tvar&amp;gt; parameter to the user that runs PHP on your web server:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;ini&amp;quot;&amp;gt;&lt;br /&gt;
[Unit]&lt;br /&gt;
Description=MediaWiki Job runner&lt;br /&gt;
&lt;br /&gt;
[Service]&lt;br /&gt;
ExecStart=/usr/local/bin/mwjobrunner&lt;br /&gt;
Nice=10&lt;br /&gt;
ProtectSystem=full&lt;br /&gt;
User=php-fpm&lt;br /&gt;
OOMScoreAdjust=200&lt;br /&gt;
StandardOutput=journal&lt;br /&gt;
&lt;br /&gt;
[Install]&lt;br /&gt;
WantedBy=multi-user.target&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:118--&amp;gt; Enable it and start it with those commands:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo systemctl enable mw-jobqueue&lt;br /&gt;
sudo systemctl start mw-jobqueue&lt;br /&gt;
sudo systemctl status mw-jobqueue&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
== Job execution on page requests == &amp;lt;!--T:6--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:7--&amp;gt; By default, at the end of each web request, one job is taken from the job queue and executed.&amp;lt;/translate&amp;gt; &lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:8--&amp;gt; This behaviour is controlled by the &amp;lt;tvar name=JobRunRate&amp;gt;&amp;lt;/tvar&amp;gt; configuration variable.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:9--&amp;gt; Setting this variable to &amp;lt;tvar name=1&amp;gt;&amp;lt;code&amp;gt;1&amp;lt;/code&amp;gt;&amp;lt;/tvar&amp;gt;, will run a job on each request.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:11--&amp;gt; Setting this variable to &amp;lt;tvar name=1&amp;gt;&amp;lt;code&amp;gt;0&amp;lt;/code&amp;gt;&amp;lt;/tvar&amp;gt; will disable the execution of jobs during web requests completely, so that you can instead run &amp;lt;tvar name=runJobs&amp;gt;&amp;lt;/tvar&amp;gt; manually or periodically from the command line.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:12--&amp;gt; When enabled, jobs will be executed by opening a socket and making an internal HTTP request to an unlisted [[&amp;lt;tvar name=man&amp;gt;Special:MyLanguage/Manual:Special pages&amp;lt;/tvar&amp;gt;|special page]]: &amp;lt;tvar name=1&amp;gt;Special:RunJobs&amp;lt;/tvar&amp;gt;.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:13--&amp;gt; See also the [[&amp;lt;tvar name=1&amp;gt;#Asynchronous&amp;lt;/tvar&amp;gt;|asynchronous section]].&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
=== Performance issue === &amp;lt;!--T:14--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:15--&amp;gt; If the performance burden of running jobs on every web request is too great but you are unable to run jobs from the command line, you can reduce &amp;lt;tvar name=JobRunRate&amp;gt;&amp;lt;/tvar&amp;gt; to a number between &amp;lt;tvar name=1&amp;gt;&amp;lt;code&amp;gt;1&amp;lt;/code&amp;gt;&amp;lt;/tvar&amp;gt; and &amp;lt;tvar name=2&amp;gt;&amp;lt;code&amp;gt;0&amp;lt;/code&amp;gt;&amp;lt;/tvar&amp;gt;.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:10--&amp;gt; This means a job will execute &amp;#039;&amp;#039;on average&amp;#039;&amp;#039; every &amp;lt;tvar name=code&amp;gt;&amp;lt;code&amp;gt;1 / $wgJobRunRate&amp;lt;/code&amp;gt;&amp;lt;/tvar&amp;gt; requests.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$wgJobRunRate = 0.01;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
=== Manual usage === &amp;lt;!--T:16--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:17--&amp;gt; There is also a way to empty the job queue manually, for example after changing a template that&amp;#039;s present on many pages.&amp;lt;/translate&amp;gt; &lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:18--&amp;gt; Simply run the &amp;lt;tvar name=RunJobs&amp;gt;&amp;lt;code&amp;gt;&amp;lt;/code&amp;gt;&amp;lt;/tvar&amp;gt; maintenance script.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:19--&amp;gt; For example:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
/path-to-my-wiki/maintenance$ php ./runJobs.php&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
== Abandoned jobs == &amp;lt;!--T:124--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:125--&amp;gt;&lt;br /&gt;
A job can fail for some reasons. To understand why, you have to inspect the related log file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:126--&amp;gt;&lt;br /&gt;
In any case, if a job fails &amp;lt;tvar name=1&amp;gt;3&amp;lt;/tvar&amp;gt; times (so if the system has done that number of attempts), the job is then considered &amp;quot;abandoned&amp;quot; and it&amp;#039;s not executed again.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:127--&amp;gt;&lt;br /&gt;
Relevant source code:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
https://doc.wikimedia.org/mediawiki-core/master/php/JobQueue_8php_source.html#l00085&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:128--&amp;gt;&lt;br /&gt;
An abandoned job is:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;translate&amp;gt;&amp;lt;!--T:129--&amp;gt; not executed anymore from &amp;lt;tvar name=1&amp;gt;&amp;lt;/tvar&amp;gt;&amp;lt;/translate&amp;gt;&lt;br /&gt;
* &amp;lt;translate&amp;gt;&amp;lt;!--T:130--&amp;gt; not counted from &amp;lt;tvar name=1&amp;gt;&amp;lt;/tvar&amp;gt;&amp;lt;/translate&amp;gt;&lt;br /&gt;
* &amp;lt;translate&amp;gt;&amp;lt;!--T:131--&amp;gt; not automatically removed from the database&amp;lt;/translate&amp;gt;&lt;br /&gt;
* &amp;lt;translate&amp;gt;&amp;lt;!--T:132--&amp;gt; but are included in the count of &amp;lt;tvar name=2&amp;gt;[[#Statistics|the statistics API module]]&amp;lt;/tvar&amp;gt;&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
== Job examples == &amp;lt;!--T:46--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Updating links tables when a template changes === &amp;lt;!--T:47--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:48--&amp;gt; When a template changes, MediaWiki adds a job to the job queue for each article transcluding that template.&amp;lt;/translate&amp;gt; &lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:49--&amp;gt; Each job is a command to read an article, expand any templates, and update the link table accordingly.&amp;lt;/translate&amp;gt; &lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:50--&amp;gt; Previously, the host articles would remain outdated until either their parser cache expires or until a user edits the article.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
=== HTML cache invalidation === &amp;lt;!--T:52--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:53--&amp;gt;&lt;br /&gt;
A wider class of operations can result in invalidation of the HTML cache for a large number of pages:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:54--&amp;gt;&lt;br /&gt;
*Changing an image (all the thumbnails have to be re-rendered, and their sizes recalculated)&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:55--&amp;gt;&lt;br /&gt;
*Deleting a page (all the links to it from other pages need to change from blue to red)&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:56--&amp;gt;&lt;br /&gt;
*Creating or undeleting a page (like above, but from red to blue)&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:57--&amp;gt;&lt;br /&gt;
*Changing a template (all the pages that transclude the template need updating)&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:58--&amp;gt; Except for template changes, these operations do not invalidate the links tables, but they do invalidate the HTML cache of all pages linking to that page, or using that image.&amp;lt;/translate&amp;gt; &lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:59--&amp;gt; Invalidating the cache of a page is a short operation; it only requires updating a single database field and sending a multicast packet to clear the caches.&amp;lt;/translate&amp;gt; &lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:60--&amp;gt; But if there are more than about 1000 to do, it takes a long time. By default, one job is added per &amp;#039;&amp;#039;&amp;#039;300&amp;#039;&amp;#039;&amp;#039; operations (see &amp;lt;tvar name=1&amp;gt;&amp;lt;/tvar&amp;gt;)&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:95--&amp;gt; Note, however, that even if purging the cache of a page is a short operation, reparsing a complex page that is not in the cache may be expensive, especially if a highly used template is edited and causes lots of pages to be purged in a short period of time and your wiki has lots of concurrent visitors loading a wide spread of pages.&amp;lt;/translate&amp;gt; &lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:96--&amp;gt; This can be mitigated by reducing the number of pages purged in a short period of time, by reducing &amp;lt;tvar name=1&amp;gt;&amp;lt;/tvar&amp;gt; to a small number (20, for example) and also set &amp;lt;tvar name=2&amp;gt;&amp;lt;/tvar&amp;gt; for &amp;lt;tvar name=3&amp;gt;&amp;lt;code&amp;gt;htmlCacheUpdate&amp;lt;/code&amp;gt;&amp;lt;/tvar&amp;gt; to a low number (5, for example).&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
=== Audio and video transcoding === &amp;lt;!--T:91--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:92--&amp;gt;&lt;br /&gt;
When using &amp;lt;tvar name=1&amp;gt;&amp;lt;/tvar&amp;gt; to process local uploads of audio and video files, the job queue is used to run the potentially very slow creation of derivative transcodes at various resolutions/formats.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:93--&amp;gt;&lt;br /&gt;
These are &amp;#039;&amp;#039;&amp;#039;not suitable&amp;#039;&amp;#039;&amp;#039; for running on web requests -- you will need a background runner.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:94--&amp;gt;&lt;br /&gt;
It&amp;#039;s recommended to set up separate runners for the &amp;lt;tvar name=1&amp;gt;&amp;lt;code&amp;gt;webVideoTranscode&amp;lt;/code&amp;gt;&amp;lt;/tvar&amp;gt; and &amp;lt;tvar name=2&amp;gt;&amp;lt;code&amp;gt;webVideoTranscodePrioritized&amp;lt;/code&amp;gt;&amp;lt;/tvar&amp;gt; job types if possible. These two queues process different subsets of files -- the first for high resolution HD videos, and the second for lower-resolution videos and audio files which process more quickly.&lt;br /&gt;
&lt;br /&gt;
== Typical values == &amp;lt;!--T:61--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:62--&amp;gt; During a period of low load, the job queue might be zero.&amp;lt;/translate&amp;gt; &lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:63--&amp;gt; At Wikimedia, the job queue is, in practice, almost never zero.&amp;lt;/translate&amp;gt; &lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:64--&amp;gt; In off-peak hours, it might be a few hundred to a thousand.&amp;lt;/translate&amp;gt; &lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:65--&amp;gt; During a busy day, it might be a few million, but it can quickly fluctuate by 10% or more.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;sup&amp;gt;[https://brionv.com/log/2008/04/22/so-whats-in-the-job-queue-anyway/]&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
== Statistics == &amp;lt;!--T:66--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:138--&amp;gt;&lt;br /&gt;
The value of the job queue can be retrieved from &amp;lt;tvar name=1&amp;gt;&amp;lt;/tvar&amp;gt;:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:69--&amp;gt; The number of jobs returned in the API result may be slightly inaccurate when using MySQL, which estimates the number of jobs in the database.&amp;lt;/translate&amp;gt; &lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:70--&amp;gt; This number can fluctuate based on the number of jobs that have recently been added or deleted.&amp;lt;/translate&amp;gt; &lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:71--&amp;gt; For other databases that do not support fast result-size estimation, the actual number of jobs is given.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
== For developers and maintainers == &amp;lt;!--T:72--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
* &lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
=== Code stewardship === &amp;lt;!--T:123--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
== History == &amp;lt;!--T:20--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Asynchronous === &amp;lt;!--T:21--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:22--&amp;gt;&lt;br /&gt;
The configuration variable &amp;lt;tvar name=RunJobsAsync&amp;gt;&amp;lt;/tvar&amp;gt; has been added to force the execution of jobs synchronously, in scenarios where making an internal HTTP request for job execution is not wanted.&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:23--&amp;gt; When running jobs asynchronously, it will open an internal HTTP connection for handling the execution of jobs, and will return the contents of the page immediately to the client without waiting for the job to complete.&amp;lt;/translate&amp;gt; &lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:24--&amp;gt; Otherwise, the job will be executed in the same process and the client will have to wait until the job is completed.&amp;lt;/translate&amp;gt; &lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:25--&amp;gt; When the job does not run asynchronously, if a fatal error occurs during job execution, it will propagate to the client, aborting the load of the page.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:26--&amp;gt; Note that even if $wgRunJobsAsync is set to true, if PHP can&amp;#039;t open a socket to make the internal HTTP request, it will fall back to the synchronous job execution.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:75--&amp;gt; However, there are a variety of situations where this internal request may fail, and jobs won&amp;#039;t be run, without falling back to the synchronous job execution.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:76--&amp;gt; Starting with MediaWiki 1.28.1 and 1.27.2, $wgRunJobsAsync now defaults to false.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
=== Deferred updates === &amp;lt;!--T:85--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:82--&amp;gt; The &amp;#039;&amp;#039;deferred updates&amp;#039;&amp;#039; mechanism allows the execution of code to be scheduled for the end of the request, after all content has been sent to the browser.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:135--&amp;gt; This is similar to queuing a job, except that it runs immediately instead of upto several minutes/hours in the future.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:81--&amp;gt; &amp;lt;tvar name=1&amp;gt;&amp;lt;code&amp;gt;DeferredUpdates&amp;lt;/code&amp;gt;&amp;lt;/tvar&amp;gt; was introduced in MediaWiki 1.23 and received major changes during MediaWiki 1.27 and 1.28.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:83--&amp;gt; The goal of this mechanism is speed up the web responses by doing less work, as well as to prioritise some work that would previously be a job to run as soon as possible after the end of the response.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:136--&amp;gt; A deferrable update can implement &amp;lt;tvar name=1&amp;gt;&amp;lt;code&amp;gt;EnqueueableDataUpdate&amp;lt;/code&amp;gt;&amp;lt;/tvar&amp;gt; in order to be queueable as a Job as well.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:137--&amp;gt; This is used by &amp;lt;tvar name=1&amp;gt;&amp;lt;code&amp;gt;RefreshSecondaryDataUpdate&amp;lt;/code&amp;gt;&amp;lt;/tvar&amp;gt; in core, for example, which means if the update fails for any reason, MediaWiki will fallback to queuing as a job and try again later as to fulfil the contract in question.&amp;lt;/translate&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
=== Changes in MediaWiki 1.22 === &amp;lt;!--T:30--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:31--&amp;gt; In &amp;lt;tvar name=mw&amp;gt;&amp;lt;/tvar&amp;gt;, the job queue execution on each page request was changed (&amp;lt;tvar name=gerrit&amp;gt;&amp;lt;/tvar&amp;gt;) so, instead of executing the job inside the same PHP process that&amp;#039;s rendering the page, a new PHP CLI command is spawned to execute &amp;lt;tvar name=runJobs&amp;gt;&amp;lt;/tvar&amp;gt; in the background.&amp;lt;/translate&amp;gt; &lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:32--&amp;gt; It will only work if &amp;lt;tvar name=PhpCli&amp;gt;&amp;lt;/tvar&amp;gt; is set to an actual path or safe mode is off, otherwise, the old method will be used.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:33--&amp;gt;&lt;br /&gt;
This new execution method could cause some problems:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:34--&amp;gt;&lt;br /&gt;
* If &amp;lt;tvar name=PhpCli&amp;gt;&amp;lt;/tvar&amp;gt; is set to an incompatible version of PHP (e.g.: an outdated version) jobs may fail to run (fixed in 1.23).&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:35--&amp;gt;&lt;br /&gt;
* PHP &amp;lt;tvar name=1&amp;gt;&amp;lt;code&amp;gt;open_basedir&amp;lt;/code&amp;gt;&amp;lt;/tvar&amp;gt; restrictions are in effect, and &amp;lt;tvar name=PhpCli&amp;gt;&amp;lt;/tvar&amp;gt; is disallowed (&amp;lt;tvar name=task&amp;gt;&amp;lt;/tvar&amp;gt;, fixed in 1.23).&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:36--&amp;gt;&lt;br /&gt;
* Performance: even if the job queue is empty, the new PHP process is started anyway (&amp;lt;tvar name=task&amp;gt;&amp;lt;/tvar&amp;gt;, fixed in 1.23).&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:37--&amp;gt;&lt;br /&gt;
* Sometimes the spawning PHP process cause the server or only the CLI process to hang due to &amp;lt;tvar name=1&amp;gt;stdout&amp;lt;/tvar&amp;gt; and &amp;lt;tvar name=2&amp;gt;stderr&amp;lt;/tvar&amp;gt; descriptors not properly redirected (&amp;lt;tvar name=task&amp;gt;&amp;lt;/tvar&amp;gt;, fixed in 1.22)&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:38--&amp;gt;&lt;br /&gt;
* It does not work for shared code (wiki farms), because it doesn&amp;#039;t pass additional required parameters to &amp;lt;tvar name=1&amp;gt;runJobs.php&amp;lt;/tvar&amp;gt; to identify the wiki that&amp;#039;s running the job (&amp;lt;tvar name=task&amp;gt;&amp;lt;/tvar&amp;gt;, fixed in 1.23)&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:39--&amp;gt;&lt;br /&gt;
* Normal shell limits like &amp;lt;tvar name=1&amp;gt;, , &amp;lt;/tvar&amp;gt; are enforced on the &amp;lt;tvar name=2&amp;gt;runJobs.php&amp;lt;/tvar&amp;gt; process that&amp;#039;s being executed in the background.&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:40--&amp;gt; There&amp;#039;s no way to revert to the old on-request job queue handling, besides setting &amp;lt;tvar name=PhpCli&amp;gt;&amp;lt;/tvar&amp;gt; to &amp;lt;tvar name=1&amp;gt;&amp;lt;code&amp;gt;false&amp;lt;/code&amp;gt;&amp;lt;/tvar&amp;gt;, for example, which may cause other problems (&amp;lt;tvar name=task&amp;gt;&amp;lt;/tvar&amp;gt;).&amp;lt;/translate&amp;gt; &lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:41--&amp;gt; It can be disabled completely by setting &amp;lt;tvar name=code&amp;gt; 0;}}&amp;lt;/tvar&amp;gt;, but jobs will no longer run on page requests, and you must explicitly run &amp;lt;tvar name=1&amp;gt;runJobs.php&amp;lt;/tvar&amp;gt; to periodically run pending jobs.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
=== Changes in MediaWiki 1.23 === &amp;lt;!--T:42--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:43--&amp;gt;&lt;br /&gt;
In MediaWiki 1.23, the 1.22 execution method is abandoned, and jobs are triggered by MediaWiki making an HTTP connection to itself.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:44--&amp;gt;&lt;br /&gt;
It was first designed as an [[&amp;lt;tvar name=man&amp;gt;Special:MyLanguage/Manual:API&amp;lt;/tvar&amp;gt;|API]] entry point (&amp;lt;tvar name=gerrit1&amp;gt;&amp;lt;/tvar&amp;gt;) but later changed to be the unlisted special page &amp;lt;tvar name=1&amp;gt;[[Special:RunJobs]]&amp;lt;/tvar&amp;gt; (&amp;lt;tvar name=gerrit2&amp;gt;&amp;lt;/tvar&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:45--&amp;gt;&lt;br /&gt;
While it solves various bugs introduced in 1.22, it still requires loading a lot of PHP classes in memory on a new process to execute a job, and also makes a new HTTP request that the server must handle.&lt;br /&gt;
&lt;br /&gt;
=== Changes in MediaWiki 1.27 === &amp;lt;!--T:86--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:87--&amp;gt;&lt;br /&gt;
In MediaWiki 1.25 and MediaWiki 1.26, use of &amp;lt;tvar name=1&amp;gt;&amp;lt;/tvar&amp;gt; would sometimes cause jobs not to get run if the wiki has custom &amp;lt;tvar name=2&amp;gt;&amp;lt;/tvar&amp;gt;  configuration. This was fixed in MediaWiki 1.27.&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
=== Changes in MediaWiki 1.28 === &amp;lt;!--T:88--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:89--&amp;gt;&lt;br /&gt;
Between MediaWiki 1.23 and MediaWiki 1.27, use of &amp;lt;tvar name=1&amp;gt;&amp;lt;/tvar&amp;gt; would cause jobs not to get run on if MediaWiki requests are for a server name or protocol that does not match the currently configured server name one (e.g. when supporting both HTTP and HTTPS, or when MediaWiki is behind a reverse proxy that redirects to HTTPS). This was fixed in MediaWiki 1.28.&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
=== Changes in MediaWiki 1.29 === &amp;lt;!--T:90--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:77--&amp;gt;&lt;br /&gt;
In MediaWiki 1.27.0 to 1.27.3 and 1.28.0 to 1.28.2, when &amp;lt;tvar name=1&amp;gt;&amp;lt;/tvar&amp;gt; is set to a value greater than 0, an error like the one below may appear in error logs, or on the page:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
PHP Notice: JobQueueGroup::__destruct: 1 buffered job(s) never inserted&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:78--&amp;gt; As a result of this error, certain updates may fail in some cases, like category members not being updated on category pages, or recent changes displaying edits of deleted pages - even if you manually run &amp;lt;tvar name=runJobs&amp;gt;&amp;lt;/tvar&amp;gt; to clear the job queue.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:79--&amp;gt; It has been reported as a bug (&amp;lt;tvar name=bug&amp;gt;&amp;lt;/tvar&amp;gt;) and was solved in 1.27.4 and 1.28.3.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Changes in MediaWiki 1.17 ===&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:67--&amp;gt; Up to MediaWiki 1.16, the job queue value was shown on &amp;lt;tvar name=1&amp;gt;[[Special:Statistics]]&amp;lt;/tvar&amp;gt;.&amp;lt;/translate&amp;gt; &lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:68--&amp;gt; Since 1.17 (&amp;lt;tvar name=rev&amp;gt;[[rev:75272]]&amp;lt;/tvar&amp;gt;) it&amp;#039;s been removed, and can be seen now with &amp;lt;tvar name=api&amp;gt;&amp;lt;/tvar&amp;gt;:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== MediaWiki 1.6 ===&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:1--&amp;gt;&lt;br /&gt;
In 2009 ([[&amp;lt;tvar name=1&amp;gt;Special:MyLanguage/Release notes/1.6&amp;lt;/tvar&amp;gt;|MediaWiki 1.6]]) the &amp;#039;&amp;#039;&amp;#039;job queue&amp;#039;&amp;#039;&amp;#039; was introduced to perform long-running tasks asynchronously.&lt;br /&gt;
&lt;br /&gt;
== See also == &amp;lt;!--T:74--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
* &lt;br /&gt;
* &lt;br /&gt;
* &lt;br /&gt;
* &lt;br /&gt;
* &lt;br /&gt;
&lt;br /&gt;
[[Category:Job queue| ]]&lt;br /&gt;
[[Category:Installation]]&lt;br /&gt;
[[Category:MediaWiki concepts]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&amp;#039;&amp;#039;Sample content adapted from [[mediawikiwiki:Manual:Job_queue]] on mediawiki.org, licensed under [https://creativecommons.org/licenses/by-sa/4.0/ CC BY-SA 4.0].&amp;#039;&amp;#039;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
</feed>