1

I'm redeveloping my online text based MMO, And I'm building a "Travel" Script Where a user clicks where they want to go and it takes X minutes to get there.

The only problem is - Due to limitations of my host, I cannot run 1 cronjob every minute to take away time spent travelling.

Can someone tell me how i could achieve this without using crons? Delaying a query from being run for multiples of 1 minute or so?

Once they set off, A countdown from that moment of X minutes begins, And once their travel time reaches 0 their "location" is set to "destination"

Thanks!

5
  • 1
    You could use a javascript like setTimeout() check the time and when your condition is met call a script that will make the query. Commented Nov 17, 2013 at 4:16
  • are you sure your model design is ok? the time left to destination should not be stored in the database i believe (but maybe I'm wrong) Commented Nov 17, 2013 at 4:19
  • so the user sits staring at the screen until the travel time is done? Commented Nov 17, 2013 at 4:22
  • @Dagon No, The User Initiates the travel by choosing a destination and then a countdown is initiated, During travel the user will be able to navigate away from that page and the timer will be displayed somewhere else. when the timer reaches 0 a query will be run to move them to their destination and then the location link will appear again. Commented Nov 18, 2013 at 4:31
  • @ElliottFrisch That's what i'm aiming for, how would i go about a query for that? Commented Nov 18, 2013 at 15:43

2 Answers 2

2

Use PHP sleep() method.

Like sleep(60); will result in the script to wait execution for 1 minute.

Do NOT set a script timeout as it wont make any sense.

Sign up to request clarification or add additional context in comments.

2 Comments

Will the user be able to navigate away from the page this is in? for example go from travel.php to chat.php without this being affected?
Yah. If you decide to redirect them. The delay can only be part of a certain method but not the whole script.
0

I suggest you add a destination time column, set it to when the animals should arrive, and then in the client display a countdown until that time. You could use a query such as

select * from arrivals where arrival_time < now();

To get a list of animals that have not yet arrived, and of course the arrival_time is when they will arrive.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.