larger smaller normal text version of this page
phplist Development

Process Queue Workflow Description


(this is a draft text, aiming to explain how the send process actually works, text based on version 2.8.12)
  • check command-line (still to document)
  • if (!$GLOBALS["commandline"]) {
  • check on test mode
  • if (TEST)
    	print '<font color=red size=5>Running in testmode, no emails will be sent. Check your config file.</font>';
  • code to manage batch sending (still to document)
  • $maxbatch = -1;
  • javascript output (still to document)
  • print '<script language="Javascript" src="js/progressbar.js" type="text/javascript"></script>';
    print formStart('name="outputform"').'<textarea name="output" rows=22 cols=75></textarea></form>';
  • definition of some functions (to document)
  • select all messages that are in the queue to be sent
  • $messages = Sql_query("select id,userselection,rsstemplate from ".$tables["message"]." where status != \"draft\" and status != \"sent\" and status != \"prepared\" and embargo < now() order by entered");
  • show how many messages will be processed
  • output("Processing has started, $num message(s) to process.");
  • iterate over these messages
  • while ($message = Sql_fetch_array($messages)) {
  • for every of those messages, do:
    • set status in process
    •   $status = Sql_query('update '.$tables["message"].' set status = "inprocess",sendstart = now() where id = '.$messageid);
    • check whether a custom userselection has been set for the message, if so, fetch those users:
    •   if ($userselection && $numattr[0]) {
    • otherwise, fetch all users subscribed to the lists the message has been sent to:
    •   $query = "select distinct {$tables['listuser']}.userid
        	from {$tables['listuser']},{$tables['listmessage']} ";
        $query .= "where {$tables['listmessage']}.messageid = $messageid and
      		{$tables['listmessage']}.listid = {$tables['listuser']}.listid $exclusion ";
    • show how many users to process:
    •  output( "Found them: $num to process");
    • limit to the max number in a batch:
    •     if ($num_per_batch > 0) {
      	  $query .= sprintf(' limit %d,%d',$reload * $num_per_batch,$num_per_batch);
      	  $userids = Sql_query("$query");
    • fetch user by user:
    • 			$users = Sql_query("select id,email,uniqid,htmlemail,rssfrequency,confirmed from {$tables['user']} where id = $userdata[0]");
      • check whether is_email($user[1]) (user's email addres is a valid email address)
      • check whether user's indicated rss frequency matches the rss frequency of the message:
      • if ($rssfrequency == $message["rsstemplate"]) {
      • fetch rss content for this user
      • $rssitems = rssUserHasContent($userid,$messageid,$rssfrequency);
      • check whether number of rss items is above threshold
      •  $cansend = sizeof($rssitems) && (sizeof($rssitems) > $rss_content_treshold);
      • (note: semantically, this should better be >= )
      • if all these conditions have been met, send the message
      • indicate in table the user has been sent this rss message
      •             Sql_Query("replace into {$tables["user_rss"]} (userid,last) values($userid,date_sub(now(),interval 15 minute))");
      • continue with next user

More on fetching rss content: the function rssUserHasContent($userid,$messageid,$rssfrequency) is being called during processqueue, for a given user, messageid and rss-frequency (that is both the users ' and the messages rss frequency!)
Execution of this function:
  • check whether there are: either
    • no messages sent for this user previously at all
    • no messages sent since intervallength (and intervallength is determined by the frequency)

	$cansend_req = Sql_Query(sprintf('select date_add(last,%s) < now() from %s where userid = %d',
	  $interval,$tables["user_rss"],$userid));
	$exists = Sql_Affected_Rows();
	$cansend = Sql_Fetch_Row($cansend_req);
  if (!$exists || $cansend[0]) {
  • then all lists are being collected
    • this message has been sent to (note there is only one rss message per frequency, so give the fact that a user has a certain frequency, there is only one message he can get rss messages by!)
    • this user is subscribed to
        $listsreq = Sql_Query(sprintf('
    		select %s.listid from %s,%s where %s.listid = %s.listid and %s.userid = %d and
    	  %s.messageid = %d',
    	  $tables["listuser"],$tables["listuser"],$tables["listmessage"],
    			$tables["listuser"],$tables["listmessage"],
    	  $tables["listuser"],$userid,$tables["listmessage"],$messageid));

  • collect the rss items from the mentioned lists, latest first
    $itemreq = Sql_Query("select {$tables["rssitem"]}.*
	    from {$tables["rssitem"]} where {$tables["rssitem"]}.list in ($liststosend) order by added desc, list,title limit $max");
	while ($item = Sql_Fetch_Array($itemreq)) {
		Sql_Query("select * from {$tables["rssitem_user"]} where itemid = {$item["id"]} and userid = $userid");
	  if (!Sql_Affected_Rows()) {
				array_push($itemstosend,$item["id"]);
	  }



CategoryDevelopment
Page was generated in 0.0561 seconds