getting a php file to run every night

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
calebsg
Forum Commoner
Posts: 28
Joined: Tue Jun 18, 2002 10:41 am

getting a php file to run every night

Post by calebsg »

I just got word from my web hosting provider that they don't do custom cron jobs.

I need a php page to run unattended and automatically every night with some database functions in it. Is there any other way to automatically execute the page on a regular basis (24/7 at midnight) without using cron?
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

well... there is probably a way, but off the top of my head.. if your computer is on (at least at midnight) you can set a task to open up the script every day at midnight
calebsg
Forum Commoner
Posts: 28
Joined: Tue Jun 18, 2002 10:41 am

Post by calebsg »

I had thought of that but the problem is that I live in the middle of nowhere (rural Saskatchewan) and so i'm on dial-up internet (no DSL available).

Any other ideas?
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

you might try... checking the time... and using an if statement

Code: Select all

<?

$var = time();
$lowtime = //10 minutes before;
$hightime = //10 minutes after;

if($var >= $lowtime && $var <= $hightime)&#123;
//do the script
&#125;

echo "<META HTTP-EQUIV=Refresh CONTENT="1200; URL=$PHP_SELF">";
?>
that would check the time and see if it was in a little range of midnight and refresh every 20 minutes
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Post by BDKR »

Do you need this script to run at home or on a server (web host or something)? If you are using Linux or some other Unix, you could use cron.

What exactly are you doing and what are the constraints placed on you by your system?

Later on,
BDKR (TRC)
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

he said "without using cron" :wink:
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Post by BDKR »

Doh! :oops:

Is it possible to find some free host that does support cron jobs? If so, have the cron job on a free host access the script you need at midnight using wget or something like that.

Another option is to have your index page check the time. If it's midnight or beyond when the page is accessed, it can also run the script.

Just some ideas....

Later on,
BDKR
User avatar
mikeq
Forum Regular
Posts: 512
Joined: Fri May 03, 2002 3:33 am
Location: Edinburgh, Scotland

Post by mikeq »

hob_goblin wrote:you might try... checking the time... and using an if statement

Code: Select all

<?

$var = time();
$lowtime = //10 minutes before;
$hightime = //10 minutes after;

if($var >= $lowtime && $var <= $hightime)&#123;
//do the script
&#125;

echo "<META HTTP-EQUIV=Refresh CONTENT="1200; URL=$PHP_SELF">";
?>
that would check the time and see if it was in a little range of midnight and refresh every 20 minutes
Yeah but who is going to run it?
calebsg
Forum Commoner
Posts: 28
Joined: Tue Jun 18, 2002 10:41 am

Post by calebsg »

Just to clarify: my site is hosted on third-party web server (blacksun.ca) who won't do custom cron jobs.

I basically want to query a database for some specific criteria and if they are met, than an email is sent to the appropriate person. I had in mind to have it run automatically at midnight so that the email would be sitting in the inbox first thing in the morning for them.

Gotta head off for the weekend here, so won't be able to reply but if you have an idea, please post it here and I will check this forum Monday.

Thanks a bunch for your efforts -- this forum (ie. all you people out there) is/are great!
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

man... i was thinking about that.. and then i guess my brain emptied and started over
FlashMan
Forum Newbie
Posts: 15
Joined: Mon Jun 24, 2002 9:50 am
Location: Russia
Contact:

Post by FlashMan »

Exist the only one way to run scripts at specific time:
If your page has many visitors, detect time of loading page, compare it with need timeof running script, if its aproximal equal then run script :lol:
rsbeaulieu
Forum Newbie
Posts: 6
Joined: Tue Jul 02, 2002 6:02 am
Location: NH

Post by rsbeaulieu »

i dont know but i did that by doing this hehe

Code: Select all

$qry = mysql_query("SELECT DateAuto FROM siteauto WHERE TO_DAYS(NOW()) - TO_DAYS(DateAuto) >= 3");
if( mysql_num_rows($qry) == 0 ) &#123;
     exit();
&#125;
using the database to pull up a time greater than 2 days ago and have it do its thing in the else statement which would also update the DateAuto = NOW()

:D
User avatar
e+
Forum Commoner
Posts: 44
Joined: Mon Jun 17, 2002 7:07 am
Location: Essex, UK

Post by e+ »

there is a nice easy way I have used to get around cron before. There is a site called http://www.internetseer.com/ who run a site downtime checking service for free. All you have to do is set up a little page that does your thing and they will visit the page every hour. This means you can have your script run every hour without using cron, simple. They even send you an e-mail to tell you if they were unable to connect to your page, you even get to see server outages as well for free along with having your script run for you.
Kind regards
Roger
User avatar
cheatboy00
Forum Contributor
Posts: 151
Joined: Sat Jun 29, 2002 10:36 am
Location: canada
Contact:

Post by cheatboy00 »

well my free host supports cron jobs
Post Reply