@@ -1178,6 +1178,41 @@ function sendEmailTest($messageid, $email)
11781178 ++$ counters ['sent_users_for_message ' .$ messageid ];
11791179 $ um = Sql_Query (sprintf ('replace into %s (entered,userid,messageid,status) values(now(),%d,%d,"sent") ' ,
11801180 $ tables ['usermessage ' ], $ userid , $ messageid ));
1181+
1182+ if ($ script_stage < 5 ) {
1183+ $ script_stage = 5 ; // we have actually sent one user
1184+ }
1185+
1186+ if (isset ($ running_throttle_delay )) {
1187+ sleep ($ running_throttle_delay );
1188+ if ($ counters ['sent ' ] % 5 == 0 ) {
1189+ // retry running faster after some more messages, to see if that helps
1190+ unset($ running_throttle_delay );
1191+ }
1192+ } elseif (MAILQUEUE_THROTTLE ) {
1193+ usleep (MAILQUEUE_THROTTLE * 1000000 );
1194+ } elseif (MAILQUEUE_BATCH_SIZE && MAILQUEUE_AUTOTHROTTLE ) {
1195+ $ totaltime = $ GLOBALS ['processqueue_timer ' ]->elapsed (1 );
1196+ $ msgperhour = (3600 / $ totaltime ) * $ counters ['sent ' ];
1197+ $ msgpersec = $ msgperhour / 3600 ;
1198+
1199+ //#11336 - this may cause "division by 0", but 'secpermsg' isn't used at all
1200+ // $secpermsg = $totaltime / $counters['sent'];
1201+ $ target = (MAILQUEUE_BATCH_PERIOD / MAILQUEUE_BATCH_SIZE ) * $ counters ['sent ' ];
1202+ $ delay = $ target - $ totaltime ;
1203+
1204+ if ($ delay > 0 ) {
1205+ if (VERBOSE ) {
1206+ /* processQueueOutput(s('waiting for').' '.$delay.' '.s('seconds').' '.
1207+ s('to make sure we don\'t exceed our limit of ').MAILQUEUE_BATCH_SIZE.' '.
1208+ s('messages in ').' '.MAILQUEUE_BATCH_PERIOD.s('seconds')); */
1209+ processQueueOutput (s ('waiting for %.1f seconds to meet target of %s seconds per message ' ,
1210+ $ delay , (MAILQUEUE_BATCH_PERIOD / MAILQUEUE_BATCH_SIZE ))
1211+ );
1212+ }
1213+ usleep ($ delay * 1000000 );
1214+ }
1215+ }
11811216 } else {
11821217 ++$ counters ['failed_sent ' ];
11831218 ++$ counters ['failed_sent_for_message ' .$ messageid ];
@@ -1204,43 +1239,6 @@ function sendEmailTest($messageid, $email)
12041239 $ GLOBALS ['tables ' ]['user ' ], $ useremail ));
12051240 }
12061241 }
1207-
1208- if ($ script_stage < 5 ) {
1209- $ script_stage = 5 ; // we have actually sent one user
1210- }
1211- if (isset ($ running_throttle_delay )) {
1212- sleep ($ running_throttle_delay );
1213- if ($ counters ['sent ' ] % 5 == 0 ) {
1214- // retry running faster after some more messages, to see if that helps
1215- unset($ running_throttle_delay );
1216- }
1217- } elseif (!$ throttled ) {
1218- // apply delay only when attempted to send, not when throttled
1219- if (MAILQUEUE_THROTTLE ) {
1220- usleep (MAILQUEUE_THROTTLE * 1000000 );
1221- } elseif (MAILQUEUE_BATCH_SIZE && MAILQUEUE_AUTOTHROTTLE ) {
1222- $ totaltime = $ GLOBALS ['processqueue_timer ' ]->elapsed (1 );
1223- $ msgperhour = (3600 / $ totaltime ) * $ counters ['sent ' ];
1224- $ msgpersec = $ msgperhour / 3600 ;
1225-
1226- //#11336 - this may cause "division by 0", but 'secpermsg' isn't used at all
1227- // $secpermsg = $totaltime / $counters['sent'];
1228- $ target = (MAILQUEUE_BATCH_PERIOD / MAILQUEUE_BATCH_SIZE ) * $ counters ['sent ' ];
1229- $ delay = $ target - $ totaltime ;
1230-
1231- if ($ delay > 0 ) {
1232- if (VERBOSE ) {
1233- /* processQueueOutput(s('waiting for').' '.$delay.' '.s('seconds').' '.
1234- s('to make sure we don\'t exceed our limit of ').MAILQUEUE_BATCH_SIZE.' '.
1235- s('messages in ').' '.MAILQUEUE_BATCH_PERIOD.s('seconds')); */
1236- processQueueOutput (s ('waiting for %.1f seconds to meet target of %s seconds per message ' ,
1237- $ delay , (MAILQUEUE_BATCH_PERIOD / MAILQUEUE_BATCH_SIZE ))
1238- );
1239- }
1240- usleep ($ delay * 1000000 );
1241- }
1242- }
1243- }
12441242 } else {
12451243 ++$ cannotsend ;
12461244 // mark it as sent anyway, because otherwise the process will never finish
0 commit comments