Changeset 16754
- Timestamp:
- 07/01/08 08:07:24 (3 months ago)
- Files:
-
- trunk/midcom/midcom.helper.replicator/queuemanager.php (modified) (10 diffs)
- trunk/midcom/midcom.helper.replicator/transporter/archive.php (modified) (1 diff)
- trunk/midcom/midcom.helper.replicator/transporter/email.php (modified) (2 diffs)
- trunk/midcom/midcom.helper.replicator/transporter/http.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/midcom/midcom.helper.replicator/queuemanager.php
r16744 r16754 13 13 class midcom_helper_replicator_queuemanager extends midcom_baseclasses_components_purecode 14 14 { 15 var $max_queues_per_pass = 10; 15 var $max_queues_per_pass = 10; // per subscription 16 var $max_items_per_pass = 3500; // per QM instance, not this is checked only *after* queue pass so more might be processed if single queue dirs are very large 17 var $_items_processed = 0; 16 18 var $exporters = array(); 17 19 var $transporters = array(); … … 532 534 foreach ($files as $item_path) 533 535 { 536 // reset time limit counter while reading files 537 set_time_limit(30); 538 534 539 $queue_item = basename($item_path); 535 540 if ( !is_readable($item_path) … … 541 546 return false; 542 547 } 543 544 // reset time limit counter while reading files545 set_time_limit(30);546 548 547 549 // Separate the indexing prefix from key in item filename … … 549 551 $items_sort[$item_key] = (int)substr($queue_item, 0, 10); 550 552 // Read item 553 /** 554 * Lets conserve memory and have the transporters read the files on-demand. 555 */ 556 $items[$item_key] = $item_path; 557 /* 551 558 $items[$item_key] = file_get_contents($item_path); 552 559 if ($items[$item_key] === false) … … 558 565 } 559 566 //$GLOBALS['midcom_helper_replicator_logger']->log("Read {$item_key} from queue \"{$subscription->title}\" file {$item_path}"); 567 */ 568 // We need this separate paths array as well even when the main items array has 560 569 $items_paths[$item_key] = $item_path; 561 570 unset($item_key, $item_path); … … 600 609 function _process_queue_queuepath(&$queue_name, &$subscription_path, &$subscription) 601 610 { 611 if ($this->_items_processed > $this->max_items_per_pass) 612 { 613 debug_push_class(__CLASS__, __FUNCTION__); 614 debug_add("Item limit of {$this->max_items_per_pass} reached, returning early.", MIDCOM_LOG_INFO); 615 debug_pop(); 616 return; 617 } 602 618 if (!$this->_process_queue_queuepath_sanitychecks($queue_name, $subscription_path)) 603 619 { … … 616 632 } 617 633 618 /**619 * TODO: Read only X items to memory at a time ?620 */621 634 $items_ret = $this->_process_queue_get_items($queue_path, $subscription); 622 635 if ($items_ret === false) … … 629 642 $items_paths =& $items_ret[1]; 630 643 644 $this->_items_processed += count($items_paths); 631 645 if (!$transporter->process($items)) 632 646 { … … 642 656 $this->_process_queue_quarantines($items, $items_paths, $subscription); 643 657 unset($items, $items_paths, $items_ret); 644 /**645 * /TODO: Read only X items to memory at a time ?646 */647 658 648 659 // Check if the queue_dir has any more items left, if not rmdir it … … 722 733 function process_queue() 723 734 { 735 $this->_items_processed = 0; 724 736 $_MIDCOM->auth->request_sudo('midcom.helper.replicator'); 725 737 debug_push_class(__CLASS__, __FUNCTION__); trunk/midcom/midcom.helper.replicator/transporter/archive.php
r15545 r16754 195 195 return false; 196 196 } 197 foreach ($items as $key => $data) 198 { 197 foreach ($items as $key => $path) 198 { 199 // Reset time limit while copying keys 200 set_time_limit(30); 199 201 $file = "{$this->_tmp_dir}/" . sprintf('%010d', $this->_file_counter) . ".xml"; 200 if ( !$this->_put_file_contents($file, $data))202 if (copy($path, $file)) 201 203 { 202 204 // In this transport any single item failure is fatal 203 205 return false; 204 206 } 205 unset($items[$key] );207 unset($items[$key], $path); 206 208 $this->_file_counter++; 207 209 } 208 return true;209 }210 211 function _put_file_contents(&$filepath, &$data)212 {213 $fp = fopen($filepath, 'w');214 if (!$fp)215 {216 return false;217 }218 if (!fwrite($fp, $data, strlen($data)))219 {220 fclose($fp);221 // PONDER: unlink file ?222 return false;223 }224 fclose($fp);225 210 return true; 226 211 } trunk/midcom/midcom.helper.replicator/transporter/email.php
r15545 r16754 70 70 71 71 $i = 1; 72 foreach ($items as $key => $ data)72 foreach ($items as $key => $path) 73 73 { 74 // Reset time limit while reading keys 75 set_time_limit(30); 74 76 $att = array 75 77 ( 76 78 'name' => sprintf('%010d', $i) . 'xml', 77 79 'mimetype' => 'text/xml', 78 'content' => $data,80 'content' => file_get_contents($path), 79 81 ); 80 82 $mail->attachments[] = $att; … … 82 84 $i++; 83 85 } 84 unset($key, $ data);86 unset($key, $path); 85 87 86 88 if (!$mail->send()) 87 89 { 88 90 // TODO: error reporting 91 unset($mail); 89 92 return false; 90 93 } 94 unset($mail); 91 95 return true; 92 96 } trunk/midcom/midcom.helper.replicator/transporter/http.php
r16736 r16754 81 81 function _post_item(&$key, &$items, $retry_count = 0) 82 82 { 83 $data =& $items[$key];84 83 $this->_client = new org_openpsa_httplib(); 85 84 $client =& $this->_client; … … 88 87 $post_vars = array 89 88 ( 90 'midcom_helper_replicator_import_xml' => &$data,89 'midcom_helper_replicator_import_xml' => file_get_contents($items[$key]), 91 90 'midcom_helper_replicator_use_force' => (int)$this->use_force, 92 91 ); 92 debug_push_class(__CLASS__, __FUNCTION__); 93 debug_add('Posting ' . strlen($post_vars['midcom_helper_replicator_import_xml']) . ' bytes to ' . $this->url); 94 debug_pop(); 93 95 $response = $client->post($this->url, $post_vars); 94 96 if ( $response !== false 95 97 && stristr($response, 'error') === false) 96 98 { 99 unset($post_vars, $response, $client); 97 100 // Key sent OK. 98 101 return true; … … 123 126 && $retry_count < 5) 124 127 { 128 unset($post_vars, $response, $client, $reponse_body, $error_string); 125 129 // Likely the remote end segfaulted, recursing to retry up-to 5 times 126 130 debug_push_class(__CLASS__, __FUNCTION__); … … 146 150 debug_add($msg, MIDCOM_LOG_WARN); 147 151 debug_print_r('Response body: ', $response_body); 148 unset($response_body);149 152 debug_pop(); 153 unset($post_vars, $response, $client, $reponse_body, $error_string); 150 154 $GLOBALS['midcom_helper_replicator_logger']->log($msg, MIDCOM_LOG_WARN); 151 155 unset($msg); … … 156 160 { 157 161 $orig_items_count = count($items); 158 foreach ($items as $key => $ data)162 foreach ($items as $key => $path) 159 163 { 160 164 if (!$this->_post_item(&$key, &$items)) … … 173 177 } 174 178 } 175 unset($key, $ data);179 unset($key, $path); 176 180 177 181 if ( !empty($items)
