Running a script at a specified time/date
Moderator: General Moderators
-
Matt Phelps
- Forum Commoner
- Posts: 82
- Joined: Fri Jun 14, 2002 2:05 pm
Running a script at a specified time/date
I'm building a newsletter that I want to email out to my subscribers at the same time each month.
I can easily do a check to see what the date/time is and if it is correct then send out the newsletter BUT I can only do that check everytime the checking script is run. Either that or I have a script constantly looping around waiting for the next valid time to send out the newsletter. That seems a bit server intensive to me.
Alternatively I guess I could have a script that runs itself everytime someone accesses the main page but what if nobody visits the site for a while - then the newsletter would be delivered late.
I'm just wondering what the best approach to this problem might be?
I can easily do a check to see what the date/time is and if it is correct then send out the newsletter BUT I can only do that check everytime the checking script is run. Either that or I have a script constantly looping around waiting for the next valid time to send out the newsletter. That seems a bit server intensive to me.
Alternatively I guess I could have a script that runs itself everytime someone accesses the main page but what if nobody visits the site for a while - then the newsletter would be delivered late.
I'm just wondering what the best approach to this problem might be?
- gite_ashish
- Forum Contributor
- Posts: 118
- Joined: Sat Aug 31, 2002 11:38 am
- Location: India
hi,
The best & most reliable solutions is to use crontab.
you need to call u r php from crontab.
for this u need to add following line in u r /etc/crontab file:
See also, some of the recent cron related posts:
http://www.devnetwork.net/forums/search.php?mode=results
PS: above crontab details (file path, syntax etc) are definitely true about Red Hat Linux 6.x/7.x, can't say about other platforms....
btw what platform u r running on ?
The best & most reliable solutions is to use crontab.
you need to call u r php from crontab.
for this u need to add following line in u r /etc/crontab file:
Will execute the script.php on 5th day of every month on 02:15 AM night.15 2 5 * * nobody /path/to/php -f /path/to/php/script.php
See also, some of the recent cron related posts:
http://www.devnetwork.net/forums/search.php?mode=results
PS: above crontab details (file path, syntax etc) are definitely true about Red Hat Linux 6.x/7.x, can't say about other platforms....
btw what platform u r running on ?
-
Matt Phelps
- Forum Commoner
- Posts: 82
- Joined: Fri Jun 14, 2002 2:05 pm
In addition to the system crontab in /etc/crontab, there is also a per user crontab. Adding a user crontab entry is not considered a "modification to the server settings " and is permitted by most hosting providers. You should check with your provider for the details of what they permit and how to set it up.
-
Matt Phelps
- Forum Commoner
- Posts: 82
- Joined: Fri Jun 14, 2002 2:05 pm
I've never heard of crontab at all and it certainly isn't mentioned in my hosts documentation, but if it involves having any other access to the server other than FTP I'm sunk. FTP and phpMyAdmin is all the access I have.tomh wrote:In addition to the system crontab in /etc/crontab, there is also a per user crontab. Adding a user crontab entry is not considered a "modification to the server settings " and is permitted by most hosting providers. You should check with your provider for the details of what they permit and how to set it up.
- hob_goblin
- Forum Regular
- Posts: 978
- Joined: Sun Apr 28, 2002 9:53 pm
- Contact:
1. Get phptriad (it comes with everything) or phpMyAdmin/Apache/MySQLMatt Phelps wrote: I have a broadband connection but I doubt that would be enough for me to run a web server from.
2. hmm, i think your all set after installation
3. type http://localhost in your browser or http://you.ip.add.here
If you have a firewall, you need to disable it to allow users to access contents of your site. I do this just to run things locally before i put it up on my site via ftp. I have no idea how it would work on a large scale, i think you would need extra RAM (max) and depending on the size of your site and HD, more gigs. Also check with your ISP to see if you have any transfer restrictions.
-
Matt Phelps
- Forum Commoner
- Posts: 82
- Joined: Fri Jun 14, 2002 2:05 pm
I already have Apache/php/MySQL running on my development laptop but it was a bugger to set up and I'm not sure what else would be involved from a security point of view - I'd be terrifed of getting my harddrive hacked by some scumbag.
Incidently - do you need to have a fixed IP? Because my IP changes constantly (something to do with the way my ISP runs things) and how do you get a domain name to point to your server?
Incidently - do you need to have a fixed IP? Because my IP changes constantly (something to do with the way my ISP runs things) and how do you get a domain name to point to your server?
Yea you need a 'dedicated' (if thats the right term for it) IP.
My ISP told me that if i payed a few bucks more per month, they would take my account of the residencial static IP plan and to the personal web server one which gives you a dedicated address and a faster line. Contact them and see if you have some similar options.
Also, anything in the htdocs folder is accessible via browser, but if you don't want somthing accessed in your htdocs folder then it's a simple process of inputting an htaccess file into your directory, and it is secure.
Works like a charm i tells ya!
My ISP told me that if i payed a few bucks more per month, they would take my account of the residencial static IP plan and to the personal web server one which gives you a dedicated address and a faster line. Contact them and see if you have some similar options.
Also, anything in the htdocs folder is accessible via browser, but if you don't want somthing accessed in your htdocs folder then it's a simple process of inputting an htaccess file into your directory, and it is secure.
Works like a charm i tells ya!
- gite_ashish
- Forum Contributor
- Posts: 118
- Joined: Sat Aug 31, 2002 11:38 am
- Location: India
hi,
i guess, we r talking around the details of web hosting.
to host a web site, one requires static ip address.
dedicated ip address and static ip address r basically two different terms, but our friendly isps uses it interchangeably to make business.
* static ip address : ofcourse the one which does not change between connections. or don't require any main server to assign the ip address. the ip address details r configured with the network interface card (nic).
for red hat linux 6.x/7.x see file: "/etc/sysconfig/network-scripts/ifcfg-eth0" for first nic details.
* dedicated ip address : single ip address can be shared by more than one web site, ie there can exist more than one web site with the same ip address. in apache it is called as "name-based virtual hosting".
in dedicated ip address hosting, ip address is not shared by web sites.
it is 1:1 ie only one ip address with one web site only.
generally, the isps charge more for dedicated hosting that shared hosting. in both type of web hosting, static ip address is used.
the domain name and ip address binding is done through dns (domain name service/server). the isps maintain the dns servers, they will do the required dns entries and will charge u accordingly.
if u r ip address changes every time u connect to internet/isp, then u r isp is using dhcp (dynamic host configuration protocol) for ip address assignment. this ip address change might be for u r internet connection and not related with web site hosting.
i guess, we r talking around the details of web hosting.
to host a web site, one requires static ip address.
dedicated ip address and static ip address r basically two different terms, but our friendly isps uses it interchangeably to make business.
* static ip address : ofcourse the one which does not change between connections. or don't require any main server to assign the ip address. the ip address details r configured with the network interface card (nic).
for red hat linux 6.x/7.x see file: "/etc/sysconfig/network-scripts/ifcfg-eth0" for first nic details.
* dedicated ip address : single ip address can be shared by more than one web site, ie there can exist more than one web site with the same ip address. in apache it is called as "name-based virtual hosting".
in dedicated ip address hosting, ip address is not shared by web sites.
it is 1:1 ie only one ip address with one web site only.
generally, the isps charge more for dedicated hosting that shared hosting. in both type of web hosting, static ip address is used.
the domain name and ip address binding is done through dns (domain name service/server). the isps maintain the dns servers, they will do the required dns entries and will charge u accordingly.
if u r ip address changes every time u connect to internet/isp, then u r isp is using dhcp (dynamic host configuration protocol) for ip address assignment. this ip address change might be for u r internet connection and not related with web site hosting.