Forum Moderators: bakedjake
I need a cron job for managing e-mail subscriptions.
So, I need execute a .php script 100 or 1000 times per 5-minutes or 10-minutes. So script'll exhaust in some definite time. I don't wanna run it all the time. But definite number of times and with definite intervals. Please help me. I'm trying my first cron.
Well, a few things...
Since you don't know how many times it actually needs to run, there's really no point in writing a crontab for this kind of script, witha preset number of times to run. Since, after all, if in one instance it needs to run 100 times, but the number of iterations is a minimum of 1000, then you're going to run a script that doesn't need to run an additional 100 times.
Secondly, I think you'd be able to run this cron at most once before your host comes to you and tells you to stop, if you're running on a shared host. If you're on a dedicated one, then whatever, it's your CPU cycles you're wasting. If you're on a shared host, your script iterating 1000 times over a 5 minute period could potentially annoy the other users and the BOFH.
Additionally, the maximum granularity of cron is per-minute. Meaning that you can at most execute something each minute. The reason for this is simple: There are other ways of doing things than having cron wake up every second and executing something. It'll kill your server pretty quick.
My recommendation would be to look at your php script. There has to be a way to rewrite it so that it doesn't need to be executed that many times in a 5 minute period. Is there a way, for example, to have your web app (or whatever) write the email subscriptions to a plain-text file, and every 5 minutes, your cron will run your PHP script, which reads the plain-text file and fires off emails to those email addresses? There's lots of people willing to help in the PHP forum as well. :)
Looking at Cron was a good place to start looking at a solution, for sure, but I don't think it'd be the best solution for this case.
HTH!
MM
To be more specific, I'm using PEAR MAIL/MIME/MAIL_QUEUE.
Yes I've the option to call PHP, until it pulls and sends all e-mails from db. But, it's better if Cron do it all the time, as I may go out and forgot to call script many times in my browser. May be I'm on a vacation or tour.
Please help me.
You mention that it's managing email subscriptions and you should know Majordomo or Mailman handles email subscription tasks much more efficiently than a script that needs to be called that many times in such a short period of time. Majordomo and Mailman are also free and require little admin intervention after they are installed.
Burner
Have cron fire off a wrapper script every 5-10 minutes. The wrapper just fires off your script, then sleeps, fires it off again, sleeps, etcetera until it reaches 100 iterations (and/or some other condition is met).