hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : PHP Cron, MySQL and Mail.
Reply

Programming Discussion Discussions related to web programming languages and other related issues. Topics may include configuration, optimization, practical usage and database connectivity.
Forum Jump

PHP Cron, MySQL and Mail.

Reply Post New Thread In Programming Discussion Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 06-06-2011, 02:13 PM
josephgarbett josephgarbett is offline
Web Hosting Master
 
Join Date: Jun 2009
Location: UK: Oxford
Posts: 1,242
Talking

PHP Cron, MySQL and Mail.


Hi everyone,

I am in need of some advice. This is not a script help request, just a MySQL sensibility question. I'm making a new website which is almost ready to launch, and part of its functionality is to send users a monthly account report.

I have come up with the idea of splitting the data processing over 2 days where on day 1, all the data is sorted into a MySQL cache table, then the next the cache is loaded and send in an email to the user.

And because the cron runs every 15 mins, this gives me 96 opportunities throughout the day before it is sent, to compile all the cache.

So, without any actual numbers as I am still making it, how many rows should I insert for the cache every 15 mins?

I was thinking around 500 every 15 mins which gives a total of 40,000 for 24 hours (And this will be tweakable at any time). I have seen on other websites queries taking 9/10 mins to perform. I can allow room for that, but I would rather not as I want to keep my nice, fully functioning website running at 100% without hitch while my cron jobs run.

I look forward to reading your sensible ideas.

__________________
Pub, Gym and Programming is now my life.


Last edited by josephgarbett; 06-06-2011 at 02:18 PM.
Reply With Quote


Sponsored Links
  #2  
Old 06-06-2011, 06:50 PM
nafirici nafirici is offline
Junior Guru Wannabe
 
Join Date: Mar 2011
Posts: 42
I had a similar issue at my job and an approach like this worked for me for a while, but then it started causing me issues. Assuming that your database is growing, right away it could work, but when you start getting hundreds of millions of records, it'll take longer to query your data to move it into a cache table and the inserts will start to put too much load on your db.

An approach that I took, was to put triggers on a couple of tables that would trigger a change in my reports. I then call a stored proc that modifies a denormalized reporting table that allows for fast reads. This isn't the best approach and does have it's limits, but by spreading the work throughout every request, i've had less problems.

__________________
Nafirici | WI Real Estate

Reply With Quote
  #3  
Old 06-07-2011, 09:55 AM
swiftyCMS swiftyCMS is offline
Newbie
 
Join Date: May 2011
Location: New Zealand
Posts: 21
Two ways to approach this; cron or no cron

If you already have 40,000 users, you can take the option not to use cron;
make a custom table for 1st, 2nd, 3rd, etc 500 users emailed.
whenever a user visits your site run the script for the next 500. mysql is very fast, email loading on your server is another issue.

Or use cron and run a php driven bash script that sends the emails. bash is not restricted by php runtime. (still using a mysql table for 1st, 2nd, 3rd, etc 500 users)

my choice; cron with bash script. bash can be executed from cron and it's quick.

Reply With Quote
Sponsored Links
  #4  
Old 06-08-2011, 02:40 AM
josephgarbett josephgarbett is offline
Web Hosting Master
 
Join Date: Jun 2009
Location: UK: Oxford
Posts: 1,242
I need the cron, theres no two ways about it. I'm having to write some real funky MySQL to do Loads of maths for me as its pulling data from about 9 different tables.

This includes basic user information, user settings, calculating Totals, averages, means and ranges for EACH user.

Every month, this data must be stored as this is the core functionality of the site. Weather the user wants the information via email is a different matter like you said, but the user still needs to be able to have access to this information. Think of it like an online archive of an account which cannot be removed by the user.

I know MySQL is fast, but its the mail bit thats the problem. Would 500 emails every 15 mins sound okay or would it clog up my server? Because I may end up having 40,000 users; but each have the ability to turn this email feature on and off.

__________________
Pub, Gym and Programming is now my life.

Reply With Quote
  #5  
Old 06-08-2011, 05:16 AM
swiftyCMS swiftyCMS is offline
Newbie
 
Join Date: May 2011
Location: New Zealand
Posts: 21
Ok, understand better now.
As you correctly stated mail is going to be the memory problem(especially if you have spamassasin or similar running), it gobbles up resources.
I don't know the specs(ram) of your server, but I would suggest starting at about 200 every 15min and keep an eye on your server.
200 should definately not be a problem - then just slowly increase it until you get to 500 if possible.
Also bear in mind that by the time you have 40,000 users you would propably(if not already) be on a dedicated server with much better specs.

Reply With Quote
  #6  
Old 06-09-2011, 02:34 AM
josephgarbett josephgarbett is offline
Web Hosting Master
 
Join Date: Jun 2009
Location: UK: Oxford
Posts: 1,242
Yes, I do have spam assasin installed. To be honest, I've given it some thought over night and will probably once I've reached 1000 users, think of moving onto a Dedicated server. And will then setup something like a Blade-cluster to send emails

The emails as I've mentioned is my main concern, because while I'm still developing and optimising it on a shared server , there will be active users and I don't want to clog up the server i'll be temporarily using.

__________________
Pub, Gym and Programming is now my life.

Reply With Quote
  #7  
Old 06-13-2011, 03:09 AM
ionisis ionisis is offline
Newbie
 
Join Date: Jun 2011
Posts: 18
IMO, if you're website is slows down when you compile 40,000 reports, then you may need to consider THAT issue first .

If your database is properly normalised, and your developer is VERY efficient, then this should all be able to do it all at 1 time (well, the emails may need to be split up over a couple of hours, but the compilation should be able to be done in 1 go), without much notice on the server's load.

Reply With Quote
Reply

Similar Threads
Thread Thread Starter Forum Replies Last Post
No Oversold Hosting starting at $1.00 / 99.9% Uptime PHP/MYSQL/CRON/CGI/Perl/ Cpanel jcarney1987 Shared Hosting Offers 0 02-03-2009 06:51 AM
RAQ3 Mail warning: Cron <root@....> run-parts /etc/cron.daily PGF Dedicated Server 1 01-11-2003 06:57 PM

Related posts from TheWhir.com
Title Type Date Posted
Jelastic Launches Version 1.9.1 of Java and PHP Hosting Platform Web Hosting News 2013-05-21 09:39:09
Web Hosting Sales and Promos Roundup – June 22, 2012 Web Hosting News 2012-06-22 16:36:15
Web Hosting Control Panel cPanel and WHM Version 11.32 Adds Features, Fixes Web Hosting News 2012-04-08 11:51:35
cPanel Launches Version 11.32 of Control Panel and Web Host Manager Web Hosting News 2012-02-15 12:46:33
Web Host Rackspace Launches Private Beta for MySQL Cloud Database Web Hosting News 2011-12-01 21:09:51


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?