Timeout Problem with MailChimp

1,380 views
Skip to first unread message

Mirx

unread,
Jul 9, 2010, 3:07:55 PM7/9/10
to MailChimp API Discuss
hi guys,
i have a problem. i mean obviously i have, thats why i am writing.
ok, my problem:

i am using the hominid gem by brian getting to subscribe and
unsubscribe from and to mailchimp.
everything is working fine so far.
but now i need a function to batch subscribe. i thought about using
the function listBatchSubscribe by mailchimp. but when i call the
function via hominid, i get a timeout around 3k - 4k addresses.
i even tried to do it one by one with the listSubscribe method. but
even here: after a couple of thousand addresses -> timeout.
is there any chance to increase the timeout limit? or am i doing
anything wrong?
i tried in all kinds of batch sizes: 10, 50, 100, 1000, 3000. no
change.
i also have a sleep in between each batch which varied between 2 secs
and 10 minutes.
many thanks in advance! i appreciate each hint or help very much!

jesse

unread,
Jul 9, 2010, 5:17:07 PM7/9/10
to MailChimp API Discuss
We don't timeout calls on our side, so you need to increase the
timeout limit hominid is using. I took a quick look through the source
and didn't immediately see a way to change that, so you may need to
post to the github issue tracker about that. I imagine adding that
option will be a quick fix.


jesse

jesse

unread,
Jul 9, 2010, 5:18:42 PM7/9/10
to MailChimp API Discuss
Oops, hit send too early. Two other things I wanted to mentioned - as
far as the API is concerned, there's no point in putting a sleep in
between calls. Also, if sizes of 100 and less didn't work, you may
have some other issue going on since those should typically complete
rather quickly, or at least quick enough to be under any built-in
default timeout.


jesse

On Jul 9, 3:07 pm, Mirx <mi...@gmx.de> wrote:

Mirx

unread,
Jul 12, 2010, 6:15:58 AM7/12/10
to MailChimp API Discuss
Jesse,
thanks a million again for your help. I'll try to figure out, if it
may be an issue of our server.
I'll post that issue on github as well.
Thanks a lot!
Mirko

Larry Kleinman

unread,
Jul 12, 2010, 12:08:12 PM7/12/10
to mailchimp-...@googlegroups.com, MailChimp API Discuss
I seem to be having the same sort of problem as Mirko.   I am only loading 8 rows from a table and sometimes it works and sometimes it does not.  I have hardcoded a SQL selection (the code is below) that selects the same 8 records.  Whenever I run it, my var_dump shows the correct 8 records in my array.  However, sometimes the script runs all the way to the end and shows me the number of successes and failures (and updates the list), and sometimes it just ends after the var_dump and does not update the list

Here's the code:

<?php
 require_once 'mailchimp/MCAPI.class.php';
 require_once 'mailchimp/fbc.config.inc.php'; //contains apikey
?>

<html>
  <head></head>
  <body>
 
    <?php    
//    $FirstName = $_POST['FirstName'];
   
   $api = new MCAPI($apikey); // For loading names to the list
   $listId = 'xxxxxxx';
   
   $conn = mssql_connect('FBC_DEV_106','xxxx','xxxx');

   if ($conn) {
          mssql_select_db("FBC_DEV_106");
          $query = "SELECT * from Name where first_name = 'Joan' and  EMAIL > ' ' ";
     
          $sql_result = mssql_query($query);

          if($sql_result) {
            while ($array = mssql_fetch_array($sql_result)) {
           
              $First = $array['FIRST_NAME'];
              $Last = $array['LAST_NAME'];
              $Email = $array['EMAIL'];
   
              $batch[] = array('EMAIL'=>$Email, 'FNAME'=>$First, 'LNAME'=>$Last);            
              $count = $count + 1;
            }  
     
          $optin = false; // no, do not send optin emails
          $up_exist = true; // yes, update currently subscribed users
          $replace_int = false; // no, add interest, don't replace  
     var_dump($batch);      
          $vals = $api->listBatchSubscribe($listId,$batch,$optin, $up_exist, $replace_int);
           if ($api->errorCode){
                echo "Batch Subscribe failed!\n";
                    echo "code:".$api->errorCode."\n";
                           echo "msg :".$api->errorMessage."\n";}
           else {
                           echo "success:".$vals['success_count']."\n";        
                           echo "errors:".$vals['error_count']."\n";        
                           foreach($vals['errors'] as $val){
                           echo $val['email_address']. " failed\n";
                           echo "code:".$val['code']."\n";
                           echo "msg :".$val['message']."\n";        }}
           
             
          }
                                         
   }
    echo $count;      
    if (!$conn) { echo "no good"; }
  ?>
 
</body>
</html>





Larry Kleinman
Kleinman Associates, Inc.
212-949-6469
203-255-4100



Mirx <mi...@gmx.de>
Sent by: mailchimp-...@googlegroups.com

07/12/2010 06:46 AM


To
MailChimp API Discuss <mailchimp-...@googlegroups.com>
cc
Subject
Re: Timeout Problem with MailChimp





--
You received this message because you are subscribed to the Google Groups "MailChimp API Discuss" group.
To post to this group, send email to mailchimp-...@googlegroups.com.
To unsubscribe from this group, send email to mailchimp-api-di...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/mailchimp-api-discuss?hl=en.


jesse

unread,
Jul 12, 2010, 3:01:16 PM7/12/10
to MailChimp API Discuss
It is doubtful that you are hitting a timeout since the MCAPI wrapper
checks for a properly returns an error if a call times out. If you're
not getting anything echo'd after the var_dump, it sounds like PHP is
just dying during that connection for some reason. You'll need to turn
on various level of error checking to make sure you can find out why.
You may also want to view source or use command line scripts as it's
possible an error message is getting swallowed and hidden since you
are running this call through the browser.


jesse

Larry Kleinman

unread,
Jul 13, 2010, 9:57:05 AM7/13/10
to mailchimp-...@googlegroups.com
OK, you were right, I was able to set some time out values and now it seems to be OK.  However, it takes a good five minutes or so to run the listbatchsubscribe API (there are about 7000 names), during which time nothing shows up on the browser to give the user any indication that something is actually happening.  Is there any way to get any data back from Mailchimp as the updates are happening, so I can do a progress bar on the browser screen?


 Larry Kleinman
Kleinman Associates, Inc.
212-949-6469
203-255-4100



jesse <je...@mailchimp.com>
Sent by: mailchimp-...@googlegroups.com

07/12/2010 03:01 PM

jesse

unread,
Jul 13, 2010, 10:05:36 AM7/13/10
to MailChimp API Discuss
No. That method - and many others - are most definitely not things
that should be run in real time in a browser. You are better off back-
grounding the job and displaying some sort of indeterminate progress
bar or simple loading indicator until it has finished.


jesse

Williams Castillo

unread,
Jul 13, 2010, 10:32:16 AM7/13/10
to mailchimp-...@googlegroups.com
I hope there were... :( What I did was make an AJAX call with it and placing a "loading" icon there.

I *think* you might try to fool mailchimp (no hard feelings, Jesse :) ):

As soon as you call the AJAX call for listBatchSubscribe(), call a second AJAX call that every, say, 30 seconds makes a listMembers() call so can know how many members are subscribed so far... and update your scrollbar accordingly.

I hope it helps,
Will

Larry Kleinman

unread,
Jul 13, 2010, 10:36:18 AM7/13/10
to mailchimp-...@googlegroups.com, mailchimp-...@googlegroups.com
I'm doing this via PHP, but the same concept should work, shouldn't it?


Larry Kleinman
Kleinman Associates, Inc.
212-949-6469
203-255-4100



Williams Castillo <edu...@gmail.com>
Sent by: mailchimp-...@googlegroups.com

07/13/2010 10:32 AM


To

Williams Castillo

unread,
Jul 13, 2010, 10:36:26 AM7/13/10
to mailchimp-...@googlegroups.com
[and update your scrollbar accordingly.]

Sorry... Obviously, I meant to say progressbar.

Williams Castillo

unread,
Jul 13, 2010, 10:41:03 AM7/13/10
to mailchimp-...@googlegroups.com
Not really... PHP is processed server-side... And you need to give your users feedback at their brwosers so you must do it client-side.

However, your AJAX calls, in fact, may call whatever server-side scripting language you want to use from the user's browser. PHP for instance.

(Byt the way.. I'm assuming you are on a web-based application. If you are using a command prompt script, that's another history).

If you are not familiar with AJAX, I would recommend you to use jQuery for this. It will make your life a lot easier.

All best,
Will
PD: Keep in mind that this method might cost you a lot of MC API calls... Try to leave enough distance between calls.

Williams Castillo

unread,
Jul 13, 2010, 10:48:08 AM7/13/10
to mailchimp-...@googlegroups.com
By the way, I guess this approach won't work when you set the Double Opt-in flag to true.

Larry Kleinman

unread,
Jul 13, 2010, 11:08:14 AM7/13/10
to mailchimp-...@googlegroups.com
OK, I'm a little lost here.   Don't know anything about AJAX or jQuery.   Yes, I understand that PHP is server side - are you saying that the server will sit on the PHP line with the listbatchsubscribe function and just stay there till it is complete, so that there is no way that I can call the listmember function till the subscribe function is done (by which point it no longer matters)?


Larry Kleinman
Kleinman Associates, Inc.
212-949-6469
203-255-4100



Williams Castillo <edu...@gmail.com>
Sent by: mailchimp-...@googlegroups.com

07/13/2010 10:48 AM

Williams Castillo

unread,
Jul 13, 2010, 11:22:46 AM7/13/10
to mailchimp-...@googlegroups.com
Yes, AJAX will allows you to make asyncronous calls to your server.

That said, you could make an asyncronous call to your server to subscribe in batch. Note: It is not a "background" job per se. If the connection brokes, for whatever reason, the call will also be broken and you won't know anything about it.

In parallel, you can make a second asyncronous call to your server that periodically check the member count of you list... until the first call ends.

With the jQuery jlibrary, to make AJAX calls is extremelly easy. Check http://jquery.com and look for the Ajax() -recommended- or Post() call.

I hope it helps.
Will
Reply all
Reply to author
Forward
0 new messages