Page 1 of 1

perform some function based on time

Posted: Wed Nov 30, 2005 2:42 am
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?

Posted: Wed Nov 30, 2005 3:19 am
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.

Posted: Wed Nov 30, 2005 3:24 am
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.

Posted: Wed Nov 30, 2005 3:29 am
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.

Posted: Wed Nov 30, 2005 3:38 am
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.

Posted: Wed Nov 30, 2005 3:53 am
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.

Posted: Wed Nov 30, 2005 4:04 am
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.

Posted: Wed Nov 30, 2005 4:14 am
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.

Posted: Wed Nov 30, 2005 4:23 am
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.

Posted: Wed Nov 30, 2005 8:43 am
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.