Special:Asksql query timeout feature
authorTim Starling <tstarling@users.mediawiki.org>
Wed, 11 Feb 2004 13:15:16 +0000 (13:15 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Wed, 11 Feb 2004 13:15:16 +0000 (13:15 +0000)
includes/killthread.php [new file with mode: 0644]

diff --git a/includes/killthread.php b/includes/killthread.php
new file mode 100644 (file)
index 0000000..05a165b
--- /dev/null
@@ -0,0 +1,36 @@
+<?
+
+# Script to kill a MySQL thread after a specified timeout
+
+$wgCommandLineMode = true;
+
+unset( $IP );
+ini_set( "allow_url_fopen", 0 ); # For security...
+include_once( "./LocalSettings.php" );
+
+# Windows requires ';' as separator, ':' for Unix
+$sep = strchr( $include_path = ini_get( "include_path" ), ";" ) ? ";" : ":";
+ini_set( "include_path", "$IP$sep$include_path" );
+
+include_once( "Setup.php" );
+
+$wgTitle = Title::newFromText( wfMsg( "badtitle" ) );
+$wgArticle = new Article($wgTitle);
+
+if ( !$argv[1] || !$argv[2] ) {
+       exit();
+}
+
+$tid = (int)$argv[2];
+
+# Wait for timeout (this process may be killed during this time)
+$us = floor( $argv[1] * 1000000 ) % 1000000;
+$s = floor( $argv[1] );
+usleep( $us );
+sleep( $s );
+
+# Kill DB thread
+$conn = Database::newFromParams( $wgDBserver, $wgDBsqluser, $wgDBsqlpassword, $wgDBname );
+$conn->query( "KILL $tid" );
+
+?>