API intermittent and unreliable. Any ideas?

Rob Bruce

New Member
Hi,
I really like mailwizz and all it offers for the price but I have issues with sites using the API. I have simple site with hosting a small form and it's working fine most of the time but often the API freezes and the site will not load or takes a very long time to load. I'd say 1in10 loads will prevent the site from loading. If I remove the API it's working fine but not very useful.

Where could I start in debugging this issue? I don't seem to have any issues with MailWizz directly only when using the API from https://github.com/twisted1919/mailwizz-php-sdk

Thanks.
 
Hi,

I used the example ajax_subscribe.php to make a form and only changed the fields to fit my form and styled it all in css. But it also displays all the current subscribers in a table on the page on each load. It is used for a high school reunion registration and only less then 100 subscribers. The site is live so I'm not sure I want to provide the link here to check directly.

I load the subscribers directly in PHP like...
$perPage = 2000 but it's only less then 100 subs.
PHP:
<table>
<?php 
   
    // GET ALL ITEMS
    $listUid    = 'ye318mcr5eba7';// you'll take this from your customers area, in list overview from the address bar.
    $endpoint   = new MailWizzApi_Endpoint_ListSubscribers();
    $response = $endpoint->getSubscribers($listUid, $pageNumber = 1, $perPage = 2000);
   
    // DISPLAY RESPONSE
    foreach ($response->body['data']['records'] as $value){
        echo "<tr><td>".$value['NOM'].", ".$value['PRENOM']."</td></tr>";
    }
   
?>
</table>

Thank you again


Hi @Rob Bruce

Do you call the api on each page load and make a call to mailwizz? If so, why ?

What is the code you're using, share so we can have a look :)
 
You can invalidate the cache after x hours or after a new subscriber has been added through your api calls.
There are plenty cache libraries you can use for this.
 
Hi again,
Thank you for the help but although caching might help it does not explain the issue about the page not loading randomly. Why would Mailwizz struggle with such small requests? When the page does load it takes <100ms with all images. I would like to be able to rely on Mailwizz but I will not use it again unless I can solve the issue and that would be sad. The site is very very low traffic... it might get 3-5 hits a day and have to load that subscription list of 40 subscribers each time. So what if there is no cache on a site like this. If I was getting 100s of hits a day I would agree with you. I still would like to know why the API is hanging in this condition ether way.

Do you have any suggestions on how to debug this? The mailwizz Application Log does not help... I have PHP logs that do not show anything. I have been watching Apache logs but nothing explains why the page will not load randomly.

Thank you again...
 
@Rob Bruce - Fair enough, let's debug this :p
In your code, right at the start of the execution, do a condition like:
PHP:
if ( $_SERVER['REMOTE_ADDR'] == 'your.ip.address.here' ) {
    ini_set('display_errors', 1);
    error_reporting(-1);
}
This will enable error reporting for you alone, so next time when the site fails to load, you should get a decent message as to why, so let's see it and we can continue from there.
 
Hi,

Thank you again for the help...

When the page hangs (1 in 20 refresh roughly... hard to say) it does not load at all not even the DOM is ready. Just the page loading indicator moving in the browser. Eventually it will timeout with an php error "WARNING: INVALID ARGUMENT SUPPLIED FOR FOREACH() IN INDEX.PHP ON LINE 171" but that is just because the response contains no data. I dumped the API response variable to my server logs and got...

Code:
[07-Apr-2017 21:26:41 UTC] MailWizzApi_Http_Response Object
(
[url] => http://my.censored.url.com/api/lists/ye318mcr5eba7/subscribers?page=1&per_page=2000
[headers] =>
[contentType] =>
[httpMessage] =>
[curlCode] => 28
[curlMessage] => connect() timed out!
[storeCurlInfo] =>
[curlInfo] =>
[body] => MailWizzApi_Params Object
(
[_data:MailWizzApi_Params:private] => Array
(
[status] => error
[error] => connect() timed out!
)

[_readOnly:MailWizzApi_Params:private] =>
)

[request] =>
[_httpCode:MailWizzApi_Http_Response:private] => 0
)

So it seems to me the MailWizz main app is not responding to the API requests for some reason how can we debug that side? MailWizz is on the same server as the site in question and the domain has a record on my internal DNS server as well as the external DNS. I've tested for DNS issues and I don't see any. Plus it's happening internal and external to our network with both local and external IPs.

Most of the time I get a health response like this...

Code:
[url] => http://my.censored.url.com/api/lists/ye458mdr5eba7/subscribers?page=1&per_page=2000
[headers] => MailWizzApi_Params Object
(
[_data:MailWizzApi_Params:private] => Array
(
[0] => HTTP/1.1 304 Not Modified
[1] => Date: Fri, 07 Apr 2017 21:30:08 GMT
[2] => Server: Apache/2.2.22 (Ubuntu)
[3] => ETag: "KMgtIZa4o5Bp8aafkItY+4rD8Dc="
[4] => Expires: Thu, 19 Nov 1981 08:52:00 GMT
[5] => Cache-Control: no-cache, must-revalidate
[6] => Set-Cookie: PHPSESSID=k5vod34t1guvr4bsbaa25no435; path=/
)

[_readOnly:MailWizzApi_Params:private] =>
)

[contentType] =>
[httpMessage] => Not Modified
[curlCode] => 0
[curlMessage] =>
[storeCurlInfo] =>
[curlInfo] =>
[body] => MailWizzApi_Params Object
(
[_data:MailWizzApi_Params:private] => Array
(
[status] => success
[data] => Array
(
[count] => 48
[total_pages] => 1
[current_page] => 1
[next_page] =>
[prev_page] =>
[records] => Array
(
[0] => Array
Lot's of healthy looking array objects...

Thank you again.

@Rob Bruce - Fair enough, let's debug this :p
In your code, right at the start of the execution, do a condition like:
PHP:
if ( $_SERVER['REMOTE_ADDR'] == 'your.ip.address.here' ) {
    ini_set('display_errors', 1);
    error_reporting(-1);
}
This will enable error reporting for you alone, so next time when the site fails to load, you should get a decent message as to why, so let's see it and we can continue from there.
 
@Rob Bruce - Do you think is possible to give me the real url (maybe via PM) so that i can also see this? It will also help some FTP access to try and debug this my way...
 
Hi,

I am going to be doing a big update this server in two weeks all new hardware and OS... I'm on an 5 year old version of Ubuntu with limited RAM. I will do this and report back on the issue if it still exists. Who knows maybe the upgrades will help. If not I will be able to give you FTP access after the event I'm collecting data for is finished.

Thank you again.
 
Hello,

So in my debugging efforts and preparing for my server updates I discovered the issue and it's now fixed. It was unrelated to MailWizz and was in fact a DNS issue the only effected this one site.

I'm very happy and MailWizz is great! Thank you for your time and hints in the debugging stuff.
 
Back
Top