Index: trunk/phase3/includes/HttpFunctions.php |
— | — | @@ -78,7 +78,7 @@ |
79 | 79 | // check if we can find phpCliPath (for doing a background shell request to php to do the download: |
80 | 80 | if( $wgPhpCli && wfShellExecEnabled() && $dl_mode == self::ASYNC_DOWNLOAD ){ |
81 | 81 | wfDebug( __METHOD__ . "\ASYNC_DOWNLOAD\n" ); |
82 | | - // setup session and shell call: |
| 82 | + //setup session and shell call: |
83 | 83 | return self::initBackgroundDownload( $url, $target_file_path, $content_length ); |
84 | 84 | } else { |
85 | 85 | wfDebug( __METHOD__ . "\nSYNC_DOWNLOAD\n" ); |
— | — | @@ -143,11 +143,14 @@ |
144 | 144 | * (a given client could have started a few http uploads at once) |
145 | 145 | */ |
146 | 146 | 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" ); |
150 | 150 | // set session to the provided key: |
151 | 151 | session_id( $session_id ); |
| 152 | + //fire up mediaWiki session system: |
| 153 | + wfSetupSession(); |
| 154 | + |
152 | 155 | // start the session |
153 | 156 | if( session_start() === false ){ |
154 | 157 | wfDebug( __METHOD__ . ' could not start session' ); |
— | — | @@ -167,8 +170,9 @@ |
168 | 171 | if( isset( $sd['orgServer'] ) && $sd['orgServer'] ){ |
169 | 172 | $wgServer = $sd['orgServer']; |
170 | 173 | } |
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(); |
173 | 177 | |
174 | 178 | $req = new HttpRequest( $sd['url'], array( |
175 | 179 | 'target_file_path' => $sd['target_file_path'], |
— | — | @@ -177,7 +181,7 @@ |
178 | 182 | 'do_close_session_update' => true |
179 | 183 | ) ); |
180 | 184 | // 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"); |
182 | 186 | $status = $req->doRequest(); |
183 | 187 | //wfDebug("done with req status is: ". $status->isOK(). ' '.$status->getWikiText(). "\n"); |
184 | 188 | |
— | — | @@ -220,7 +224,7 @@ |
221 | 225 | $printer->execute(); |
222 | 226 | $apiUploadResult = ob_get_clean(); |
223 | 227 | |
224 | | - wfDebug( __METHOD__ . "\n\n got api result:: $apiUploadResult \n" ); |
| 228 | + //wfDebug( __METHOD__ . "\n\n got api result:: $apiUploadResult \n" ); |
225 | 229 | // the status updates runner will grab the result form the session: |
226 | 230 | $sd['apiUploadResult'] = $apiUploadResult; |
227 | 231 | } |
— | — | @@ -430,7 +434,6 @@ |
431 | 435 | |
432 | 436 | public function doPhpReq(){ |
433 | 437 | global $wgTitle, $wgHTTPProxy; |
434 | | - |
435 | 438 | # Check for php.ini allow_url_fopen |
436 | 439 | if( !ini_get( 'allow_url_fopen' ) ){ |
437 | 440 | return Status::newFatal( 'allow_url_fopen needs to be enabled for http copy to work' ); |
— | — | @@ -461,7 +464,6 @@ |
462 | 465 | 'timeout' => $this->timeout ) |
463 | 466 | ) |
464 | 467 | ); |
465 | | - |
466 | 468 | $fh = fopen( $this->url, "r", false, $fcontext); |
467 | 469 | |
468 | 470 | // set the write back function (if we are writing to a file) |
— | — | @@ -473,12 +475,11 @@ |
474 | 476 | return $status; |
475 | 477 | } |
476 | 478 | |
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) |
478 | 480 | while ( !feof( $fh ) ) { |
479 | 481 | $contents = fread( $fh, 65536 ); |
480 | 482 | $cwrite->callbackWriteBody( $fh, $contents ); |
481 | 483 | } |
482 | | - |
483 | 484 | $cwrite->close(); |
484 | 485 | // check for simpleFileWriter error: |
485 | 486 | if( !$cwrite->status->isOK() ){ |
— | — | @@ -543,7 +544,6 @@ |
544 | 545 | $wgLang->formatSize( $wgMaxUploadSize ) . ' ' ); |
545 | 546 | return 0; |
546 | 547 | } |
547 | | - |
548 | 548 | // if more than session_update_interval second have passed update_session_progress |
549 | 549 | if( $this->do_close_session_update && $this->upload_session_key && |
550 | 550 | ( ( time() - $this->prevTime ) > $this->session_update_interval ) ) { |
— | — | @@ -559,13 +559,16 @@ |
560 | 560 | } |
561 | 561 | |
562 | 562 | public function update_session_progress(){ |
| 563 | + global $wgSessionsInMemcached; |
563 | 564 | $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 | + } |
568 | 571 | } |
569 | | - $sd =& $_SESSION['wsDownload'][$this->upload_session_key]; |
| 572 | + $sd =& $_SESSION['wsDownload'][ $this->upload_session_key ]; |
570 | 573 | // check if the user canceled the request: |
571 | 574 | if( isset( $sd['user_cancel'] ) && $sd['user_cancel'] == true ){ |
572 | 575 | //@@todo kill the download |
— | — | @@ -573,10 +576,11 @@ |
574 | 577 | } |
575 | 578 | // update the progress bytes download so far: |
576 | 579 | $sd['loaded'] = $this->current_fsize; |
| 580 | + |
577 | 581 | // close down the session so we can other http queries can get session updates: |
| 582 | + if( !$wgSessionsInMemcached ) |
| 583 | + session_write_close(); |
578 | 584 | |
579 | | - session_write_close(); |
580 | | - |
581 | 585 | return $status; |
582 | 586 | } |
583 | 587 | |