* There's no more need for this here than anywhere else..
[mediawiki.git] / includes / killthread.php
blobb12eccb9e935c7caddfbcc50c15780b9fde5811b
1 <?php
2 /**
3 * Script to kill a MySQL thread after a specified timeout
4 * @package MediaWiki
5 * @subpackage Database
6 */
8 /**
11 if( php_sapi_name() != 'cli' ) {
12 die('');
15 define( 'MEDIAWIKI', 1 );
16 $wgCommandLineMode = true;
18 unset( $IP );
19 ini_set( 'allow_url_fopen', 0 ); # For security...
20 require_once( '../LocalSettings.php' );
22 if( !$wgAllowSysopQueries ) {
23 die( "Queries disabled.\n" );
26 require_once( 'Setup.php' );
28 $wgTitle = Title::newFromText( wfMsgForContent( 'badtitle' ) );
29 $wgArticle = new Article($wgTitle);
31 if ( !$argv[1] || !$argv[2] ) {
32 exit();
35 $tid = (int)$argv[2];
37 # Wait for timeout (this process may be killed during this time)
38 $us = floor( $argv[1] * 1000000 ) % 1000000;
39 $s = floor( $argv[1] );
40 usleep( $us );
41 sleep( $s );
43 # Kill DB thread
44 $conn = Database::newFromParams( $wgDBserver, $wgDBsqluser, $wgDBsqlpassword, $wgDBname );
45 $conn->query( 'KILL '.$tid );