How to repeat mysql query every X seconds. For egzample X is $seconds . But I need to do this even then page is not opened. I use MySQL database and I need to add 1point of smth every $seconds . I'm creating browser based game , but this is huge problem when counting resources. Any ideas?
I don't think you'd be able to do it in PHP as the piece of script would have to be run in order for it to happen. However, if you make a seperate script and include it in every other script therefore, that piece of scripture would run yet the page would never be opened. I've confused myself writing this, so it'll probably confuse you even more
Your best off using a crontab to run your script every second. There are ways to so it strictly with php, but in your case this would be the equivalent of an intentional memory leak, since you would have no control over the script after it begins execution. What sounds like a better idea, and I think that NateJ was thinking the same thing, is that you use a user executed script, so that when they load a new page, it would add the amount needed based on the last page timestamp. Basically if they looked at a page 50 seconds ago, it would add 50 to their total. By using this method you don't continuously use resources, and you don't risk creating memory leaks.
Hello , If you have a cPanel , you can do it with Horn Jobs , or through php script by calling Linux command ...
Yep, by Cpanel you can set up a cron job. But, we aware! most hosting providers in their TOS, say clearly "min cronjob's time: 15 minutes" (Like mine XD), for prevent abuse. So, read your provider TOS carrefull
As belier said, most hosting providers have a set minimum execution time when it comes to cron jobs, so it's recommended that you use a User executed script.