Changeset 16754

Show
Ignore:
Timestamp:
07/01/08 08:07:24 (3 months ago)
Author:
rambo
Message:

forward port r16753

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/midcom/midcom.helper.replicator/queuemanager.php

    r16744 r16754  
    1313class midcom_helper_replicator_queuemanager extends midcom_baseclasses_components_purecode 
    1414{ 
    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; 
    1618    var $exporters = array(); 
    1719    var $transporters = array(); 
     
    532534        foreach ($files as $item_path) 
    533535        { 
     536            // reset time limit counter while reading files 
     537            set_time_limit(30); 
     538 
    534539            $queue_item = basename($item_path); 
    535540            if (   !is_readable($item_path) 
     
    541546                return false; 
    542547            } 
    543  
    544             // reset time limit counter while reading files 
    545             set_time_limit(30); 
    546548 
    547549            // Separate the indexing prefix from key in item filename 
     
    549551            $items_sort[$item_key] = (int)substr($queue_item, 0, 10); 
    550552            // Read item 
     553            /** 
     554             * Lets conserve memory and have the transporters read the files on-demand. 
     555             */ 
     556            $items[$item_key] = $item_path; 
     557            /* 
    551558            $items[$item_key] = file_get_contents($item_path); 
    552559            if ($items[$item_key] === false) 
     
    558565            } 
    559566            //$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  
    560569            $items_paths[$item_key] = $item_path; 
    561570            unset($item_key, $item_path); 
     
    600609    function _process_queue_queuepath(&$queue_name, &$subscription_path, &$subscription) 
    601610    { 
     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        } 
    602618        if (!$this->_process_queue_queuepath_sanitychecks($queue_name, $subscription_path)) 
    603619        { 
     
    616632        } 
    617633 
    618         /** 
    619          * TODO: Read only X items to memory at a time ? 
    620          */ 
    621634        $items_ret = $this->_process_queue_get_items($queue_path, $subscription); 
    622635        if ($items_ret === false) 
     
    629642        $items_paths =& $items_ret[1]; 
    630643 
     644        $this->_items_processed += count($items_paths); 
    631645        if (!$transporter->process($items)) 
    632646        { 
     
    642656        $this->_process_queue_quarantines($items, $items_paths, $subscription); 
    643657        unset($items, $items_paths, $items_ret); 
    644         /** 
    645          * /TODO: Read only X items to memory at a time ? 
    646          */ 
    647658 
    648659        // Check if the queue_dir has any more items left, if not rmdir it 
     
    722733    function process_queue() 
    723734    { 
     735        $this->_items_processed = 0; 
    724736        $_MIDCOM->auth->request_sudo('midcom.helper.replicator'); 
    725737        debug_push_class(__CLASS__, __FUNCTION__); 
  • trunk/midcom/midcom.helper.replicator/transporter/archive.php

    r15545 r16754  
    195195            return false; 
    196196        } 
    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); 
    199201            $file = "{$this->_tmp_dir}/" . sprintf('%010d', $this->_file_counter) . ".xml"; 
    200             if (!$this->_put_file_contents($file, $data)) 
     202            if (copy($path, $file)) 
    201203            { 
    202204                // In this transport any single item failure is fatal 
    203205                return false; 
    204206            } 
    205             unset($items[$key]); 
     207            unset($items[$key], $path); 
    206208            $this->_file_counter++; 
    207209        } 
    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); 
    225210        return true; 
    226211    } 
  • trunk/midcom/midcom.helper.replicator/transporter/email.php

    r15545 r16754  
    7070 
    7171        $i = 1; 
    72         foreach ($items as $key => $data
     72        foreach ($items as $key => $path
    7373        { 
     74            // Reset time limit while reading keys 
     75            set_time_limit(30); 
    7476            $att = array 
    7577            ( 
    7678                'name' => sprintf('%010d', $i) . 'xml', 
    7779                'mimetype' => 'text/xml', 
    78                 'content' => $data
     80                'content' => file_get_contents($path)
    7981            ); 
    8082            $mail->attachments[] = $att; 
     
    8284            $i++; 
    8385        } 
    84         unset($key, $data); 
     86        unset($key, $path); 
    8587 
    8688        if (!$mail->send()) 
    8789        { 
    8890            // TODO: error reporting 
     91            unset($mail); 
    8992            return false; 
    9093        } 
     94        unset($mail); 
    9195        return true; 
    9296    } 
  • trunk/midcom/midcom.helper.replicator/transporter/http.php

    r16736 r16754  
    8181    function _post_item(&$key, &$items, $retry_count = 0) 
    8282    { 
    83         $data =& $items[$key]; 
    8483        $this->_client = new org_openpsa_httplib(); 
    8584        $client =& $this->_client; 
     
    8887        $post_vars = array 
    8988        ( 
    90             'midcom_helper_replicator_import_xml' => &$data
     89            'midcom_helper_replicator_import_xml' => file_get_contents($items[$key])
    9190            'midcom_helper_replicator_use_force' => (int)$this->use_force, 
    9291        ); 
     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(); 
    9395        $response = $client->post($this->url, $post_vars); 
    9496        if (   $response !== false 
    9597            && stristr($response, 'error') === false) 
    9698        { 
     99            unset($post_vars, $response, $client); 
    97100            // Key sent OK. 
    98101            return true; 
     
    123126            && $retry_count < 5) 
    124127        { 
     128            unset($post_vars, $response, $client, $reponse_body, $error_string); 
    125129            // Likely the remote end segfaulted, recursing to retry up-to 5 times 
    126130            debug_push_class(__CLASS__, __FUNCTION__); 
     
    146150        debug_add($msg, MIDCOM_LOG_WARN); 
    147151        debug_print_r('Response body: ', $response_body); 
    148         unset($response_body); 
    149152        debug_pop(); 
     153        unset($post_vars, $response, $client, $reponse_body, $error_string); 
    150154        $GLOBALS['midcom_helper_replicator_logger']->log($msg, MIDCOM_LOG_WARN); 
    151155        unset($msg); 
     
    156160    { 
    157161        $orig_items_count = count($items); 
    158         foreach ($items as $key => $data
     162        foreach ($items as $key => $path
    159163        { 
    160164            if (!$this->_post_item(&$key, &$items)) 
     
    173177            } 
    174178        } 
    175         unset($key, $data); 
     179        unset($key, $path); 
    176180         
    177181        if (   !empty($items)