views:

53

answers:

2

Hi,

I had to develop a newsletter manager with JS + PHP + MYSQL and I would like to know a few things on browser timing out the JS functions. If I'm running a recursive function that delays a call to itself (while PHP returns a list of email), how can I be sure that the browser wont timeout this JS function ?

I'm asking this, because I remember using a similar newsletter manager, that while doing the ajax requests, after a few calls, it stoped without any aparent reason. I know JS is not ment for this, and I should use Crontab on server, but, I can't assume the users server handles cron, so I had to stick with JS + php.

PS - This didnt happened on this app yet, I'm just trying to prevent the worse of the scenarios (since I've tested a newsletter manager, that worked the same as this one I'm developing). Since my dummy email list is small and the delays between calls are also small, this works just fine, but let's imagine a 1,000 contact list, with a delay between sends of 120 seconds: Sending 30 emails for each 2 minutes.

By the way, why this ? Well, many hosting servers has a limit on emails sent per day or hour and this helps preventing violating that policy.

Thanks for your time any comment on this subject is appreciated ;D

A: 

from the mootools standpoint, there are several possible solutions here.

has plenty of options that allow for handling batches of jobs, look at it like a more complex .periodical (setInterval) that understands async nature of the result and can compensate for lag etc. I think it can literally do what you set in your requirements out of the box, all you need is an oncomplete callback that clears up the done from your pending array (for eg).

basically, setup all your requests to handle the chunks of data and pass them on to Request.Queue to handle sequentially. Probably less sophisticated from the point of view of sending rate control.

Dimitar Christoff
A: 

How about a meta refresh. That will not cause a timeout in your javascript function. You Just reload your page after a specific time and then send the next emails out. Adding a parameter to the URL you can find out which "round" you are on.

Can this do the job for you?

Kau-Boy