jjrjr1
Posts: 942
|
| Posted: 11/13/2008, 10:18 PM |
|
Hi
Just wanted to share this with everyone.
We had a requirement to send e-mails to all members in a table but also be able to select which members would get an e-mail such as opt out active etc.
Another requirement was that when you hit the send e-mail function you did not just sit at that page waiting for all the e-mails to process. Additionally it should not bring the server to it's knees in performance.
Here is a solution. This shows how to kick off a background process with a mass e-mail send application.
It can be adapted to any process you might want to run in the background just apply the same concepts as described.
http://ccselite.com/forums_topics_view.php?forum_id=2&forum_topic_id=25
Hope you find this useful.
Have Fun
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
TonyReid
Posts: 159
|
| Posted: 11/14/2008, 4:02 AM |
|
Not a bad concept.
I personally think your ccgetparam for OK is not enough to prevent spammers utilising the script though.
You could improve it by using a queuing system of sorts - so that it will only send so many mails per hour.
_________________
-----------
PHP/indy Game Developer - http://www.AbsoluteBreeze.co.uk |
 |
 |
jjrjr1
Posts: 942
|
| Posted: 11/14/2008, 4:51 AM |
|
Thanks for the feedback Tony.
Limiting it to so may an hour, however, would significantly reduce it's usefulness as a mas mail script. Particularly since we are using it to notify of forum posts wherethe e-mails need to go out right away.
The issue of a spammer using it does exist, but the risk is very very low. A spammer would have to know too many things like the exact name of the script, the name of the OK value, including the value of the OK Param and the names of the other parameters.
I think thst is enough security and one could even add check for the subject and message values be non NULL values.
Also, this is as much a demonstration of kicking of a background process in CCS as a how to do mass e-mail. The e-mail implementation is just an example of how to use it.
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
TonyReid
Posts: 159
|
| Posted: 11/14/2008, 7:07 AM |
|
For forum notifications, then queuing really shouldn't be much of a problem. Large forum systems such as SMF2(see my sig) use queuing and I believe phpbb3 does also.
On one of my forums I send out around 6000 emails a day of notification emails - however when I do newsletters it creeps up to around 20,000 emails a day. When it comes to mass mailing of newsletters I think using a queuing system is a must - especially if your mail server is on a shared host.
Luckily for me - I own my own servers.... but many people do not.
I see what you mean about the spamming protection, but perhaps adding non alpha sanitation for the ccgetparam's and also a referrer check might offer additional protection.
Really sorry if I am sounding negative - I don't mean to be... just thought I'd offer some constructive thoughts :)
_________________
-----------
PHP/indy Game Developer - http://www.AbsoluteBreeze.co.uk |
 |
 |
jjrjr1
Posts: 942
|
| Posted: 11/14/2008, 7:22 AM |
|
Not at all
Your feedback is great.
Don't you think the sleep(3) after every 10 emails suffices as queuing. It give control back to the OS after every 10 mails or what ever you set the $hold max vakue to.
The spamming issue, you can set those values to anyting you want. ANy parm name any value. Also you can check for existence of the other parameters which no one would know the name of. My experience with referer is not all hosts provide that.
Like I said. this is more of an illustration for kicking off a background process using CCS. Mass e-mail is just one possible implementation.
Again, Thanks for your input. Let me know if you think the sleep(3) achieves the pacing you are talking about
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
TonyReid
Posts: 159
|
| Posted: 11/14/2008, 7:54 AM |
|
I'm not sure the sleep would make that much difference, your mail server will have built in queuing to protect itself. My main concern would be the resources(particularly memory and processor usage) that the script uses to perform the mail operation on a shared server - as thats what the hosts would be concerned with.
I just found this which has some reasons to use queuing : http://wiki.mantisbt.org/doku.php/mantisbt:setting_up_mail_queuing
Thinking about it, with queuing, you could prioritise the mails so that they go out in the users time zone.... or indeed in batches. Like a single message with a list of 10 updated topics rather than 10 separate emails. It would be so much more efficient.
_________________
-----------
PHP/indy Game Developer - http://www.AbsoluteBreeze.co.uk |
 |
 |
jjrjr1
Posts: 942
|
| Posted: 11/14/2008, 10:28 AM |
|
Thanks again Tony.
I'll look into queuing and also what exactly sleep() does.
Have fun
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
mamboBROWN
Posts: 1713
|
| Posted: 11/16/2008, 7:33 AM |
|
jjrjr1
Have you thought about adding this to the Tips&Solutions forum??
|
 |
 |
laneoc
Posts: 154
|
| Posted: 11/16/2008, 11:33 AM |
|
I've been wondering about a way to kick off background processes. This looks like a great approach. I've having trouble with it, however, and looking for a way to find my problem.
- I built a page "IR_Email.php" to send email. If I bring up that page in a browser, it works.
- I built a page "IR_Base.php" which has an AfterUpdate action to invoke that page as a background process.
- I added backgroundProcess as a function in Common.php.
- I verified that backgroundProcess is being invoked upon AfterUpdate. However I cannot determine a way to isolate my problem with the backgroundProcess function. It does not produce any output; it only invokes (or fails to invoke) the IR_Email.php page.
Any tips on troubleshooting this?
Lane
_________________
Lane |
 |
 |
jjrjr1
Posts: 942
|
| Posted: 11/16/2008, 4:33 PM |
|
Hi
Does you e-mail program take URL parameters to select which record's e-mail addresses to use?
If so remember that backgroudProcess uses the post method and you need to get those parameters accordingly like with CCGetparam("parameter")
To debug your background process to be sure it is kicking off as expected ad into your e-mail program sonewhere a hard coded e-mail to yourself just using the PHP mail() function. That will at least let you know the program is executing.
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |