|
|
|
|
![]() ![]() |
Mar 17 2008, 09:20 AM
Post
#1
|
|
|
Kinda N00B Group: Members Posts: 219 Joined: 13-January 08 From: Sweden Member No.: 27,579 |
Hey! Is there any way to make a script run, even if no user is online. Because at the moment, my scripts run, only when a user is online.
And another thing: How can i make the following: (this is just an example) mysql_query"SELECT maxhp FROM users WHERE username = 'allusers'"; How can I select all users maxhp, in the same query? Thanks //Feelay |
|
|
|
Mar 17 2008, 10:38 AM
Post
#2
|
|
|
Way Out Of Control - You need a life :) Group: [HOSTED] Posts: 1,021 Joined: 2-August 05 From: Kapellen (Antwerp, Belgium) Member No.: 7,585 |
About the query, you have to do this:
SELECT maxhp FROM users This returns a list with all the maxhp's from every user in the database. You can run through this list using while or foreach. Check out example #2 here:http://us2.php.net/mysql_query Your first problem can be solved using cron-jobs, but I've never used them so I don't know how you can configure them |
|
|
|
Mar 17 2008, 11:14 AM
Post
#3
|
|
|
Kinda N00B Group: Members Posts: 219 Joined: 13-January 08 From: Sweden Member No.: 27,579 |
Is cronjobs the only solution?
and I have tried the query you gave me. But then, when I want to make every users hp to maxhp, everyone gets the highest maxhp in the table.. This post has been edited by Feelay: Mar 17 2008, 11:15 AM |
|
|
|
Mar 17 2008, 01:31 PM
Post
#4
|
|
|
Premium Member Group: [HOSTED] Posts: 476 Joined: 5-November 06 Member No.: 17,016 |
Is cronjobs the only solution? More or less, cron job is the only reliable solution. I've came across this before when I was developing a web based hotel management software, where I need to charge each room with daily charges pass midnight. The only way to guarantee that it's charge, or the code to charge runs properly and on time is by using cron. Of cause this is only for linux based machine or server. If you're running a windows server or running on your local windows machine, you can use Schedule Task, and set the script to recurring. The only set back is that you need to start the task manually for the first time if you happen to restart your pc. I do not know of any other workaround for that, so I wrote a .Net System Service, which runs in the background and check for schedule to run, much like cron, and it will run even without login. For cron, you can refer to -> http://en.wikipedia.org/wiki/Cron Cron is the service that execute the scheduled task, while you need use crontab to add/edit/remove the tasks from cron. If you're referring to astahost' hosting, you can access "Cron Jobs" from cpanel. Choose standard, the rest is quite straight forward. The command, you can either call php and pass the path to the script, or for my case I use wget, which fetch the output from an URL. So I wrote my script to output some status or response, wget will fetch it, and from the command, I redirect the output to a log file. That way I can easily keep track of the output. For cpanel, you can also choose to have the output send to your email address. But I would rather choose to check back from time to time instead of having my mail box filled up with logs(my script needs to be run every minutes). CODE wget -q -O- http://login.astahost.com/myscript.php >> /home/login/log/script.log More or less like that, I can't remember the exact command. Anyway, I chose to use wget instead of php(commandline version), due to the fact that my script can't run properly in commandline, can't figure out what's wrong, so I chose the easier method. |
|
|
|
Mar 17 2008, 01:44 PM
Post
#5
|
|
|
Premium Member Group: [HOSTED] Posts: 476 Joined: 5-November 06 Member No.: 17,016 |
Forgotten to mention the less reliable ways.
1. Use http://www.webcron.org/index.php?&lang=en. It wil lcall your URL/script at the preset time 2. Do the same as webcron, but from your own pc, or someone else pc which is one 24/7, using either schedule task or cron if you're running linux 3. Make the script intelligent, and call it from every link possible from your website, or from ajax scripted on our client side. You need to keep track of the execution of the script, so it will skip when it doesn't need to be run. Your site will need to have certain amount of traffic in order to use this method, and if not done properly, it will bog down the server. Also, it doesn't guarantee execution of the script at exactly the right timing. I don't recommend using any of these methods, unless you really have no choice, especially the 3rd one. |
|
|
|
Mar 17 2008, 02:06 PM
Post
#6
|
|
|
Whitest Black Mage Group: [MODERATOR] Posts: 1,323 Joined: 20-May 05 From: NB, Canada Member No.: 5,281 |
Just curious, but is there a particular reason you don't want to use a cron job? Using php for maintenance without user interaction might be tricky since usually it only runs when a user is accessing the site. however if their is a significant reason that you dont want to or can't use a cron job then I can see why it'd be worth looking into.
|
|
|
|
Mar 17 2008, 04:14 PM
Post
#7
|
|
|
Premium Member Group: [HOSTED] Posts: 476 Joined: 5-November 06 Member No.: 17,016 |
Just curious, but is there a particular reason you don't want to use a cron job? Using php for maintenance without user interaction might be tricky since usually it only runs when a user is accessing the site. however if their is a significant reason that you dont want to or can't use a cron job then I can see why it'd be worth looking into. There're cases where we run windows server, which doesn't have cron job. I would always use cron job on linux machine. Some hosting might not provide access to cron job. |
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 5th September 2008 - 11:40 PM |