Jump to content

Running code every 24Hrs


Ruddy

Recommended Posts

Hey guys,

 

I dont know if you can do this in PHP due to it only running when the page loads but I would like to make it so at the end of everyday "24:00" some code will run that will reset all users "Mana" and "Health".

 

My guess would be JQuery or somthing like that?

 

If anyone knows would be great for a reply.

 

Cheers guys,

Ruddy

Link to comment
Share on other sites

Right, see if i got this right.

 

You go to that file and set it so on a date/time of your choice it will run a file that you choose?

 

If that is right I cannot find the file to set another file to run at a time I choose.

 

If im wrong could you explain?

 

Cheers,

Ruddy.

Link to comment
Share on other sites

The cron file defines a pattern of time to run the file.  It's 6 fields separated by spaces/tab:

minute	hour	dayOfMonth	month	dayOfWeek	command to run

 

The minute field defines upon which minute each hour it will run.  So if you set it to say 15, it will run only when the current time has a minute equal to 15.

 

The hour field defines the hour it will run.  This is based on a 24-hour clock so 0 is midnight, 23 is 11pm.  if you set it to say 14 it would only run when it's 2pm.

 

Day of month is the day of each month.  say you set it to 1, it will only run if it's the first of the month

 

month defines which months it will run.  Say you set it to 7, it would only run in july.

 

dayOfWeek is the weekday (sun through sat) that it runs.  Sunday=0 Saturday=6.

 

finally command is that you want it to do.

 

What you do is create a combination of those fields that specifies what schedule you want.  You can use range values, or * to mean all possible values.  You'll need to read the documentation to find out all the details.  Some examples (excluding command):

*	*	*	*	*	

Would run once every minute, 24/7/365.

 

5	17	*	*	*

Would run at 5:05pm every day.

 

 

0,30	*	*	*	*

would run every hour on the hour and at the half hour (eg 1:00, 1:30, 2:00, 2:30, ...)

 

15	5	1	*	*

would run on the first of each month at 5:15 am.

 

 

If that is right I cannot find the file to set another file to run at a time I choose.

 

If you have shell access through SSH, try running the command crontab -e.  If you do not have shell access, you may be able to edit it through your hosting provider's control panel.  If you have to use their control panel to edit it, they may provide a simplified interface to make it easier to define the schedule.

 

Link to comment
Share on other sites

You'd make your PHP file that does whatever you need it to do, then you enter in for the command something to run the PHP file.  Usually you will be able to run the file via the php-cli program, so you'd have a command like:

/usr/bin/php /path/to/your/file.php

 

You'll need to find out from your host the specifics though, such as where the php program is located, or if you have to use something else like wget or lynx

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.