perform some function based on time

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
jaylin
Forum Commoner
Posts: 68
Joined: Fri Nov 18, 2005 4:44 am

perform some function based on time

Post by jaylin »

it is possible to do a function automatically based on time.
for example.

perform the action of the function called myfun on 12:00 AM everyday.

is it possible?
wh33t
Forum Newbie
Posts: 12
Joined: Wed Nov 30, 2005 2:09 am

Post by wh33t »

absolutely. You could run php in application mode... You'll have to search that up.

Or

You could run a shell script at the shell level if yur rocking some variant of linux/unix. uhh, yeah you'll have to search that up too.

Or perhaps you could have a javascript clock written into an html document use the SetTimeOut() function that automatically loads myfun.php at a given time which could have myfun() inside it.
jaylin
Forum Commoner
Posts: 68
Joined: Fri Nov 18, 2005 4:44 am

Post by jaylin »

my idea is that in myfun() these will perform.
1. access the records from mysql
2. produce a report
3. send the report to the admin by email
4. the procedures must be at 12:00 pm

so, i think these may require something that is different from ur answer. may b ur right. if so, plz tell me the way (code or link)
wh33t wrote:absolutely. You could run php in application mode... You'll have to search that up.

Or

You could run a shell script at the shell level if yur rocking some variant of linux/unix. uhh, yeah you'll have to search that up too.

Or perhaps you could have a javascript clock written into an html document use the SetTimeOut() function that automatically loads myfun.php at a given time which could have myfun() inside it.
wh33t
Forum Newbie
Posts: 12
Joined: Wed Nov 30, 2005 2:09 am

Post by wh33t »

Well I'm not too sure about application mode, but I'm pretty sure what it does is allow a php script to run like an object oriented language like C... but very minimally. Probably a bit of over kill for what you need.

Oh I know what you could do...

Just have a Scheduled Event in windows, that loads up webbrowser that runs yur php script at noon. Thats probably the easiest.
jaylin
Forum Commoner
Posts: 68
Joined: Fri Nov 18, 2005 4:44 am

Post by jaylin »

plz put some code or some links to prove ur word
wh33t wrote:Well I'm not too sure about application mode, but I'm pretty sure what it does is allow a php script to run like an object oriented language like C... but very minimally. Probably a bit of over kill for what you need.

Oh I know what you could do...

Just have a Scheduled Event in windows, that loads up webbrowser that runs yur php script at noon. Thats probably the easiest.
wh33t
Forum Newbie
Posts: 12
Joined: Wed Nov 30, 2005 2:09 am

Post by wh33t »

Ummm I cant really do that seeing how a WINDOWS SCHEDULED EVENT is created from the control Panel in windows.

Basically what I'm saying is go to http://www.yourwebsite.com/myfun.php <-- create a shortcut to the on your desktop.

Set up your Scheduled Event in windows to run that short cut at the time you desire.

But I do have a question. Do you often come in here for help and expect people to write you whole scripts to solve your problem? And do they actually do that? Cause that would be new to me.
jaylin
Forum Commoner
Posts: 68
Joined: Fri Nov 18, 2005 4:44 am

Post by jaylin »

sorry .. i misunderstand my words. my need is do on the web server!
wh33t wrote:Ummm I cant really do that seeing how a WINDOWS SCHEDULED EVENT is created from the control Panel in windows.

Basically what I'm saying is go to http://www.yourwebsite.com/myfun.php <-- create a shortcut to the on your desktop.

Set up your Scheduled Event in windows to run that short cut at the time you desire.

But I do have a question. Do you often come in here for help and expect people to write you whole scripts to solve your problem? And do they actually do that? Cause that would be new to me.
wh33t
Forum Newbie
Posts: 12
Joined: Wed Nov 30, 2005 2:09 am

Post by wh33t »

You will probably have to use a shell script then. Assuming your webserver is a linux or unix machine. You'll have to head over to a different forum probably as this doesn't have a whole lot to do with programming. But there still might be an easier way to do this.

Consider heading over to:

http://linuxquestions.org/ and going into their forums. Its a great community, go there and ask about shell scripts or cron jobs and they might have some better suggestions. Sorry I dont have any code for you.
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Post by foobar »

Use a cronjob service such as http://www.cronjob.de

Or...

If you don't need it to be done _exactly_ at 12, you can just check if the last time (saved in a text file) the function was run was >24 hours ago. If so, run it.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

if you have Cpanel on your webserver then just find the link that says cron jobs (or somthing similar) and follow the steps. it will set it up then at that specific time each day it will run that script automatically.
Post Reply