Running a script at a specified time/date

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

Matt Phelps
Forum Commoner
Posts: 82
Joined: Fri Jun 14, 2002 2:05 pm

Running a script at a specified time/date

Post by Matt Phelps »

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?
User avatar
gite_ashish
Forum Contributor
Posts: 118
Joined: Sat Aug 31, 2002 11:38 am
Location: India

Post by gite_ashish »

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:
15 2 5 * * nobody /path/to/php -f /path/to/php/script.php
Will execute the script.php on 5th day of every month on 02:15 AM night.

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

Post by Matt Phelps »

My site is hosted so I can't make any modifications to the server settings unfortunately.

As an aside - y'know I'm amazed the amount of people on here who seem to run their own servers. I have a broadband connection but I doubt that would be enough for me to run a web server from.
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

If you have good enough spec you can make your own server. Also you cannot do the thing you said by just using PHP...
tomh
Forum Newbie
Posts: 1
Joined: Sat Sep 07, 2002 3:21 pm

Post by tomh »

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.
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

Is there anything similar for Windows? :roll:
Matt Phelps
Forum Commoner
Posts: 82
Joined: Fri Jun 14, 2002 2:05 pm

Post by Matt Phelps »

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.
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.
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

Takuma wrote:Is there anything similar for Windows? :roll:
yes, it's called "task manager"
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

Matt Phelps wrote: I have a broadband connection but I doubt that would be enough for me to run a web server from.
1. Get phptriad (it comes with everything) or phpMyAdmin/Apache/MySQL
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.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

btw for a short while i ran a web game on my personal server and i have DSL connection, users said it was fast depending on how many people where online, so cable is ok, but i recommend an ultra quick line like t1 or t3 if you want to go commercial.
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

hob_goblin wrote:
Takuma wrote:Is there anything similar for Windows? :roll:
yes, it's called "task manager"
Right! Thanks!... :oops:
Matt Phelps
Forum Commoner
Posts: 82
Joined: Fri Jun 14, 2002 2:05 pm

Post by Matt Phelps »

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?
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

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. 8)

Works like a charm i tells ya! :P
User avatar
gite_ashish
Forum Contributor
Posts: 118
Joined: Sat Aug 31, 2002 11:38 am
Location: India

Post by gite_ashish »

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.
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

You can still host a site with none-static IP address. :wink:
Post Reply