barefootsanders Posted April 16, 2007 Share Posted April 16, 2007 Hey everyone. I'm programming a game in which I would like an event to happen every hour. For example I would like to update a certain stat by one every hour. Can anyone point me in the right direction as in how to achieve this? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/47281-php-time-based-scritps-help/ Share on other sites More sharing options...
veridicus Posted April 16, 2007 Share Posted April 16, 2007 Assuming it's a unix-like server, write any script and set a cron job to run it. You can write a PHP script which is called from the command line. There's plenty of cron documentation online. Quote Link to comment https://forums.phpfreaks.com/topic/47281-php-time-based-scritps-help/#findComment-230631 Share on other sites More sharing options...
HoTDaWg Posted April 16, 2007 Share Posted April 16, 2007 Assuming it's a unix-like server, write any script and set a cron job to run it. You can write a PHP script which is called from the command line. There's plenty of cron documentation online. interesting, i would love to learn about this ability however i am on a shared cpanel-utilizing host. is this still possible? HoTDaWg Quote Link to comment https://forums.phpfreaks.com/topic/47281-php-time-based-scritps-help/#findComment-230637 Share on other sites More sharing options...
barefootsanders Posted April 16, 2007 Author Share Posted April 16, 2007 Assuming it's a unix-like server, write any script and set a cron job to run it. You can write a PHP script which is called from the command line. There's plenty of cron documentation online. Is there a way to set one of these up through phpmyadmin or can you only create one through direct MySQL inputs? Quote Link to comment https://forums.phpfreaks.com/topic/47281-php-time-based-scritps-help/#findComment-230672 Share on other sites More sharing options...
veridicus Posted April 16, 2007 Share Posted April 16, 2007 My shared host allows it. I have SSH access and use crontab at the command line to set up my cron jobs. I don't know about cpanel but I assume it's up to the specific host. One side note: my shared host seems to limit CPU usage for crons. So if you have an intensive or long-running script some hosts have their systems set up to terminate them. Quote Link to comment https://forums.phpfreaks.com/topic/47281-php-time-based-scritps-help/#findComment-230673 Share on other sites More sharing options...
veridicus Posted April 16, 2007 Share Posted April 16, 2007 Is there a way to set one of these up through phpmyadmin or can you only create one through direct MySQL inputs? It has nothing to do with mysql. You can write a script in PHP (or other languages) which connects to mysql and edits records, then have a cron run that script periodically. Quote Link to comment https://forums.phpfreaks.com/topic/47281-php-time-based-scritps-help/#findComment-230677 Share on other sites More sharing options...
barefootsanders Posted April 16, 2007 Author Share Posted April 16, 2007 Is there a way to set one of these up through phpmyadmin or can you only create one through direct MySQL inputs? It has nothing to do with mysql. You can write a script in PHP (or other languages) which connects to mysql and edits records, then have a cron run that script periodically. I understand that, however I am unsure on how to write a cron and how to enable that cron through phpmyadmin. Any help would be apprecaited. Quote Link to comment https://forums.phpfreaks.com/topic/47281-php-time-based-scritps-help/#findComment-230716 Share on other sites More sharing options...
per1os Posted April 16, 2007 Share Posted April 16, 2007 The only problem with what veridicus says is that someone HAS to hit a page every so often for that cronjob to be ran. Let's say no one hits a webpage for 3 days, none of those jobs are going to be ran because there is nothing to execute that code. That is the handy thing about having access to shell console on linux, they have true cronjobs that WILL run every so many minutes. A workaround is to host the cronjob on a separate site (search for cronjob hosting) and have it run a page on your site, that way you are sure that page will be ran without having to slow users down etc. Quote Link to comment https://forums.phpfreaks.com/topic/47281-php-time-based-scritps-help/#findComment-230719 Share on other sites More sharing options...
barefootsanders Posted April 16, 2007 Author Share Posted April 16, 2007 The only problem with what veridicus says is that someone HAS to hit a page every so often for that cronjob to be ran. Let's say no one hits a webpage for 3 days, none of those jobs are going to be ran because there is nothing to execute that code. That is the handy thing about having access to shell console on linux, they have true cronjobs that WILL run every so many minutes. A workaround is to host the cronjob on a separate site (search for cronjob hosting) and have it run a page on your site, that way you are sure that page will be ran without having to slow users down etc. How do you know if you have access to the shell console on linux? Quote Link to comment https://forums.phpfreaks.com/topic/47281-php-time-based-scritps-help/#findComment-230846 Share on other sites More sharing options...
veridicus Posted April 17, 2007 Share Posted April 17, 2007 The only problem with what veridicus says is that someone HAS to hit a page every so often for that cronjob to be ran. Let's say no one hits a webpage for 3 days, none of those jobs are going to be ran because there is nothing to execute that code. That is the handy thing about having access to shell console on linux, they have true cronjobs that WILL run every so many minutes. I was referring to server cron jobs, not hoping a page gets hit. PHP scripts can be run at the command line, so they can also be called from server cron jobs on the local host. How do you know if you have access to the shell console on linux? Assuming you're on a shared web host, check for "SSH access" to your account. Some hosts also distinctly advertise the ability to run cron jobs. Quote Link to comment https://forums.phpfreaks.com/topic/47281-php-time-based-scritps-help/#findComment-231212 Share on other sites More sharing options...
SkyRanger Posted April 17, 2007 Share Posted April 17, 2007 You can run cron job no problem in cPanel. Just log into your cPpanel account and click on the Cron Jobs Icon and set up your cron using either the Standard or Advanced (Unix Style) and set it to when you want the script to run and how often. You can find more information on this by searching the net with your favorite search engine for using cron for cpanel, or check the cPanel site, they should have some information. Quote Link to comment https://forums.phpfreaks.com/topic/47281-php-time-based-scritps-help/#findComment-231297 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.