• Advertisement
Sign in to follow this  

php cron question

This topic is 4254 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

ok... before i give the question that i posted in another forum, heres the scoop, i am making a php game that is text-based, turn-based, and browser-based, i am programming it on a win 2k pro computer, and will have a linux server. Now the question(simplified!): How do you do cron, and do i really need to use program that targets a page like every 5 minutes or something? Or is there a type of script like javascript, that no one needs to view the page for it to do it, or is there a way to set the database to do it on its own.

Share this post


Link to post
Share on other sites
Advertisement
Your best bet is either a cron job or just a local server application that goes through and updates the database. Most PHP scripts will terminate after n minutes (depending on your server configuration) iirc.

For the former, you'll need to modify your crontab file (or use the at command in Unix); this is more of a question for Everything Unix, but feel free to read the intro to cron.

Share this post


Link to post
Share on other sites
Windows does not have a cron system. It does have windows scheduler, which is not as efficient as it's cron counterpart. You can write similar code for running scripts in the command line, the argument generally follows the style of:

php -f somepath

An alternative method is to spawn seperate processes for time intensive operations like processing many hundreads of turn actions based on the next time a page is run.

Alternatively, I do not suggest that you use the sleep function in php, because in windows it is not very well implemented. (Sleep works better on linux, ditto for crons..)

Share this post


Link to post
Share on other sites
If you are trying to "update" the game, you can have javascript ask the server for more data every X increments of time. That's a lot easier on the server too. This sounds like a job for AJAX. If you haven't already, look into it's fundamental technologies and see if it works for your situation.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement