r54965 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r54964‎ | r54965 | r54966 >
Date:20:39, 13 August 2009
Author:dale
Status:ok
Tags:
Comment:
added memchached compatibility to background downloads.
Modified paths:
  • /trunk/phase3/includes/HttpFunctions.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/HttpFunctions.php
@@ -78,7 +78,7 @@
7979 // check if we can find phpCliPath (for doing a background shell request to php to do the download:
8080 if( $wgPhpCli && wfShellExecEnabled() && $dl_mode == self::ASYNC_DOWNLOAD ){
8181 wfDebug( __METHOD__ . "\ASYNC_DOWNLOAD\n" );
82 - // setup session and shell call:
 82+ //setup session and shell call:
8383 return self::initBackgroundDownload( $url, $target_file_path, $content_length );
8484 } else {
8585 wfDebug( __METHOD__ . "\nSYNC_DOWNLOAD\n" );
@@ -143,11 +143,14 @@
144144 * (a given client could have started a few http uploads at once)
145145 */
146146 public static function doSessionIdDownload( $session_id, $upload_session_key ){
147 - global $wgUser, $wgEnableWriteAPI, $wgAsyncHTTPTimeout, $wgServer;
148 - wfDebug( __METHOD__ . "\n\ndoSessionIdDownload:\n\n" );
149 -
 147+ global $wgUser, $wgEnableWriteAPI, $wgAsyncHTTPTimeout, $wgServer,
 148+ $wgSessionsInMemcached, $wgSessionHandler, $wgSessionStarted;
 149+ wfDebug( __METHOD__ . "\n\n doSessionIdDownload :\n\n" );
150150 // set session to the provided key:
151151 session_id( $session_id );
 152+ //fire up mediaWiki session system:
 153+ wfSetupSession();
 154+
152155 // start the session
153156 if( session_start() === false ){
154157 wfDebug( __METHOD__ . ' could not start session' );
@@ -167,8 +170,9 @@
168171 if( isset( $sd['orgServer'] ) && $sd['orgServer'] ){
169172 $wgServer = $sd['orgServer'];
170173 }
171 - // close down the session so we can other http queries can get session updates:
172 - session_write_close();
 174+ // close down the session so we can other http queries can get session updates: (if not $wgSessionsInMemcached)
 175+ if( !$wgSessionsInMemcached )
 176+ session_write_close();
173177
174178 $req = new HttpRequest( $sd['url'], array(
175179 'target_file_path' => $sd['target_file_path'],
@@ -177,7 +181,7 @@
178182 'do_close_session_update' => true
179183 ) );
180184 // run the actual request .. (this can take some time)
181 - wfDebug( __METHOD__ . 'do Request: ' . $sd['url'] . ' tf: ' . $sd['target_file_path'] );
 185+ wfDebug( __METHOD__ . 'do Session Download :: ' . $sd['url'] . ' tf: ' . $sd['target_file_path'] . "\n\n");
182186 $status = $req->doRequest();
183187 //wfDebug("done with req status is: ". $status->isOK(). ' '.$status->getWikiText(). "\n");
184188
@@ -220,7 +224,7 @@
221225 $printer->execute();
222226 $apiUploadResult = ob_get_clean();
223227
224 - wfDebug( __METHOD__ . "\n\n got api result:: $apiUploadResult \n" );
 228+ //wfDebug( __METHOD__ . "\n\n got api result:: $apiUploadResult \n" );
225229 // the status updates runner will grab the result form the session:
226230 $sd['apiUploadResult'] = $apiUploadResult;
227231 }
@@ -430,7 +434,6 @@
431435
432436 public function doPhpReq(){
433437 global $wgTitle, $wgHTTPProxy;
434 -
435438 # Check for php.ini allow_url_fopen
436439 if( !ini_get( 'allow_url_fopen' ) ){
437440 return Status::newFatal( 'allow_url_fopen needs to be enabled for http copy to work' );
@@ -461,7 +464,6 @@
462465 'timeout' => $this->timeout )
463466 )
464467 );
465 -
466468 $fh = fopen( $this->url, "r", false, $fcontext);
467469
468470 // set the write back function (if we are writing to a file)
@@ -473,12 +475,11 @@
474476 return $status;
475477 }
476478
477 - // read $fh into the simpleFileWriter (grab in 64K chunks since its likely a media file)
 479+ // read $fh into the simpleFileWriter (grab in 64K chunks since its likely a ~large~ media file)
478480 while ( !feof( $fh ) ) {
479481 $contents = fread( $fh, 65536 );
480482 $cwrite->callbackWriteBody( $fh, $contents );
481483 }
482 -
483484 $cwrite->close();
484485 // check for simpleFileWriter error:
485486 if( !$cwrite->status->isOK() ){
@@ -543,7 +544,6 @@
544545 $wgLang->formatSize( $wgMaxUploadSize ) . ' ' );
545546 return 0;
546547 }
547 -
548548 // if more than session_update_interval second have passed update_session_progress
549549 if( $this->do_close_session_update && $this->upload_session_key &&
550550 ( ( time() - $this->prevTime ) > $this->session_update_interval ) ) {
@@ -559,13 +559,16 @@
560560 }
561561
562562 public function update_session_progress(){
 563+ global $wgSessionsInMemcached;
563564 $status = Status::newGood();
564 - // start the session (if nessesary)
565 - if( @session_start() === false){
566 - wfDebug( __METHOD__ . ' could not start session' );
567 - exit( 0 );
 565+ // start the session (if necessary)
 566+ if( !$wgSessionsInMemcached ){
 567+ if( @session_start() === false){
 568+ wfDebug( __METHOD__ . ' could not start session' );
 569+ exit( 0 );
 570+ }
568571 }
569 - $sd =& $_SESSION['wsDownload'][$this->upload_session_key];
 572+ $sd =& $_SESSION['wsDownload'][ $this->upload_session_key ];
570573 // check if the user canceled the request:
571574 if( isset( $sd['user_cancel'] ) && $sd['user_cancel'] == true ){
572575 //@@todo kill the download
@@ -573,10 +576,11 @@
574577 }
575578 // update the progress bytes download so far:
576579 $sd['loaded'] = $this->current_fsize;
 580+
577581 // close down the session so we can other http queries can get session updates:
 582+ if( !$wgSessionsInMemcached )
 583+ session_write_close();
578584
579 - session_write_close();
580 -
581585 return $status;
582586 }
583587

Status & tagging log