doing a cron job (5th post)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
m2babaey
Forum Contributor
Posts: 364
Joined: Sun May 20, 2007 9:26 am

doing a cron job (5th post)

Post by m2babaey »

Hi
You have seen some sites email members that their account is going to expire in 1 week send email notifications.
Do that sites check the whole database everyday?
secondly, how to send mass mail with php?
thanks
Last edited by m2babaey on Tue Jul 24, 2007 6:09 am, edited 1 time in total.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

You can run a cron job every night that queries the database for members expiring within x number of days, sends them an email, then sets a database field such as "expire_notified" to 1 for true.

You can use swiftmailer for mass mailings.
m2babaey
Forum Contributor
Posts: 364
Joined: Sun May 20, 2007 9:26 am

Post by m2babaey »

if it is my own site, i may search the database manually every night.
but when I'm going to do it for my client I should set it to work automatically ( it's not a project of my client! i have no customer right now! i just wana learn. thanks)
dirkr
Forum Newbie
Posts: 20
Joined: Sat Jul 07, 2007 2:55 pm

Post by dirkr »

thats what the cron job would do..
http://en.wikipedia.org/wiki/Cron

just write a php script that does a check for the accounts . .and call that script with a cronjob that will run daily or whenever you want
m2babaey
Forum Contributor
Posts: 364
Joined: Sun May 20, 2007 9:26 am

Post by m2babaey »

Thanks ( first i thought cron means stupid! :lol: :lol: :oops: )
I saw cron job in my cpanel
There I can choose the time for the job. and just remains the command input field.
It that going to be filled with a sql statement?
please give me a sample command line assuming database articles with username: m2babaey and password: pass123
I really need it :roll:
I wish I could insert the following code in the command field:

Code: Select all

<?php
$result=mysql_query("select* from table where expiredate-7<now()");
while($row=mysql_fetch_array($result)){
mail( $row['email'] , "Reminder" , "Please act for rebilling ASAP" , "admin@billing.com");
}
?>
Is it possible?
and one other thing will I need swift mailer If I use cron job to mail?
Thanks
Last edited by m2babaey on Tue Jul 24, 2007 6:27 am, edited 1 time in total.
m2babaey
Forum Contributor
Posts: 364
Joined: Sun May 20, 2007 9:26 am

Post by m2babaey »

I learnt something
I will create a php file with the code above and save it in my root directory ( or should I save it in public html?)
Then How can I call that php file to be executed? ( what should be the command line?)
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

Put something similar in your command field

Code: Select all

/usr/bin/php /path/to/cron.php
The first part should be the path that contains your php executable, the second part should be the absolute path to the php cron script.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
m2babaey
Forum Contributor
Posts: 364
Joined: Sun May 20, 2007 9:26 am

Post by m2babaey »

seperated by spaces?
Post Reply