Ruddy Posted February 28, 2012 Share Posted February 28, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/257896-running-code-every-24hrs/ Share on other sites More sharing options...
batwimp Posted February 28, 2012 Share Posted February 28, 2012 If you are using a Linux-based system, you would set up a cron job. If you are using a Windows based system, use the scheduler to run your .php script at the interval you want. http://en.wikipedia.org/wiki/Cron Quote Link to comment https://forums.phpfreaks.com/topic/257896-running-code-every-24hrs/#findComment-1321874 Share on other sites More sharing options...
Ruddy Posted February 28, 2012 Author Share Posted February 28, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/257896-running-code-every-24hrs/#findComment-1321880 Share on other sites More sharing options...
kicken Posted February 28, 2012 Share Posted February 28, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/257896-running-code-every-24hrs/#findComment-1321885 Share on other sites More sharing options...
Ruddy Posted February 28, 2012 Author Share Posted February 28, 2012 I get ya, but how would I get it to run a SQL statement in a PHP file? Quote Link to comment https://forums.phpfreaks.com/topic/257896-running-code-every-24hrs/#findComment-1321905 Share on other sites More sharing options...
kicken Posted February 28, 2012 Share Posted February 28, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/257896-running-code-every-24hrs/#findComment-1321919 Share on other sites More sharing options...
Monkuar Posted February 28, 2012 Share Posted February 28, 2012 make a field called "time" and update it every day, and then check if it's ran out of seconds, then re do query, while re-doing query throw in the replenish hp/mana query also Quote Link to comment https://forums.phpfreaks.com/topic/257896-running-code-every-24hrs/#findComment-1321922 Share on other sites More sharing options...
Ruddy Posted February 28, 2012 Author Share Posted February 28, 2012 I got it to work a while ago. Thanks so much for the help! Quote Link to comment https://forums.phpfreaks.com/topic/257896-running-code-every-24hrs/#findComment-1321927 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.