Making Things "Automatic"

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
Mr. Tech
Forum Contributor
Posts: 205
Joined: Tue Feb 11, 2003 4:18 pm
Location: Australia

Making Things "Automatic"

Post by Mr. Tech »

Hi!

I have a script that records statistics and want it to send the statistic to me via email everyday automatically without me even visiting the site.

How would I get it to send it to me automatically?

Thanks

Ben
jmarcv
Forum Contributor
Posts: 131
Joined: Tue Jul 29, 2003 7:17 pm
Location: Colorado

Post by jmarcv »

Its called a 'cron' on Unix systems. Unfortunately, many hosts do not allow php to be run from the command line, which is how yiou would have to do it, and if yours doesn't option 2 is to learn Perl or C and write one, or hire someone to do it for you.
Option 3 is to put a machine in the closet with a browser always open to your script and use Javascript timers, PHP sleep command, or time checking to tell it when to run the script. But, as I said, unless your ISP allows php from a command line.....
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

or you can also have cron call wget or lynx to some "secret" web page tp trigger a web-verison of what should be a cli process..

Of course if a search engine finds your "secret" page you might start getting loads of stat rebuilds/emails.
jmarcv
Forum Contributor
Posts: 131
Joined: Tue Jul 29, 2003 7:17 pm
Location: Colorado

Post by jmarcv »

nielsene

Hmmm... I'll look into that. I too once wanted to avoid perl.

Of course, we just had the discussion on the problems with $HTTP_REFERER, but you could probably check the IP to make sure it is only triggered internally?
Drachlen
Forum Contributor
Posts: 153
Joined: Fri Apr 25, 2003 1:16 am

Post by Drachlen »

Although this system isnt perfect, and does depend on traffic, you could set up a script that is at the top of the page and always running no matter where the user is on the site. set up a time stamp field, and have it check it each page. once its at the time you want, submit the stats to you through email. This is what im using for deleting old accounts and logging people off when they arent active, so far it works fine... Or you could put together a javascript clock and when it reaches zero have it forward to the execute page, and have a header on the execute page to go back to the clock, and just run this on the server, not sure if it could slow anything down if its only done once every 24 hours...
Mr. Tech
Forum Contributor
Posts: 205
Joined: Tue Feb 11, 2003 4:18 pm
Location: Australia

Post by Mr. Tech »

hmmm... I didn't realise it would be so hard... I noticed a program called phpAdsNew was able to send emails at any time...
jmarcv
Forum Contributor
Posts: 131
Joined: Tue Jul 29, 2003 7:17 pm
Location: Colorado

Post by jmarcv »

Mr. Tech wrote:hmmm... I didn't realise it would be so hard... I noticed a program called phpAdsNew was able to send emails at any time...
Yeah, well what does that have to do with it? You don't know how they do it. They are probably just using a listserv or something.

Not hard. Hell, I've read a lot of easy options here.
Post Reply