Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> Make A Script Run Even If No User Is Online
Feelay
post Mar 17 2008, 09:20 AM
Post #1


Kinda N00B
Group Icon

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
Go to the top of the page
 
+Quote Post
wutske
post Mar 17 2008, 10:38 AM
Post #2


Way Out Of Control - You need a life :)
Group Icon

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 tongue.gif .
Go to the top of the page
 
+Quote Post
Feelay
post Mar 17 2008, 11:14 AM
Post #3


Kinda N00B
Group Icon

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
Go to the top of the page
 
+Quote Post
faulty.lee
post Mar 17 2008, 01:31 PM
Post #4


Premium Member
Group Icon

Group: [HOSTED]
Posts: 476
Joined: 5-November 06
Member No.: 17,016



QUOTE(Feelay @ Mar 17 2008, 07:14 PM) *
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.
Go to the top of the page
 
+Quote Post
faulty.lee
post Mar 17 2008, 01:44 PM
Post #5


Premium Member
Group Icon

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.

Go to the top of the page
 
+Quote Post
Jeigh
post Mar 17 2008, 02:06 PM
Post #6


Whitest Black Mage
Group Icon

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.
Go to the top of the page
 
+Quote Post
faulty.lee
post Mar 17 2008, 04:14 PM
Post #7


Premium Member
Group Icon

Group: [HOSTED]
Posts: 476
Joined: 5-November 06
Member No.: 17,016



QUOTE(Jeigh @ Mar 17 2008, 10:06 PM) *
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.
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Outspark's Fiesta Online(1)
  2. Online Multiplayer Game(16)
  3. Center Update(5)
  4. Free Action Game Online(0)
  5. Zoho Writer(5)
  6. Credit System V2.0 Online(17)
  7. Real Driving(17)
  8. Make Your Own FPS Game(32)
  9. Online Board Games(2)
  10. User Account Control(6)
  11. How To Make A Text Based Online Game Script ?(23)
  12. How To: Display A Members/user List.(3)
  13. Is It Possible To Make Php Scripts Executed Without A Cron?(2)
  14. Myspace Gold Script(2)
  15. Slavehack(12)
  1. Free Online Speed Test(12)
  2. Make Money Online With Cashcrate - A Scam?(4)
  3. How To Make A Private Message System.(9)
  4. Battle Dawn(2)
  5. PHP: Writing A Generic Login And Register Script(14)
  6. How Can I Play World Of Warcraft For Free ?(15)
  7. Looking For Script(5)
  8. Anyone Willing To Make A Text-based Game With Me?(4)
  9. How To Run A Proxy On a Web-Server?(20)
  10. Ran Online(2)
  11. Make It Impossible To View Page Source(11)
  12. Auto-click Script(7)
  13. Powerpoint Based Games!(18)
  14. Conquer Online(10)
  15. Yahoo! Messenger Power User(1)


 



- Lo-Fi Version Time is now: 5th September 2008 - 11:40 PM