shortysbest Posted February 4, 2011 Share Posted February 4, 2011 If I have setInterval at a 1 second delay would it cause the browser/computer to use a lot more ram/cpu then if it were to be 10 seconds, or 60 seconds? Like enough that it could cause problems with somebodies computer. Also, for loading new comments into the page as they come would it be better to use setInterval, or setTimeout and just trigger the function at the end of it so it would act the same as interval just not trigger until it has completed the query. Quote Link to comment https://forums.phpfreaks.com/topic/226725-does-setinterval-use-a-lot-of-ramcpu-if-you/ Share on other sites More sharing options...
.josh Posted February 5, 2011 Share Posted February 5, 2011 If you are wanting something to be run every X seconds indefinitely, use setInterval() instead of setTimeout(). They are practically the same thing but with setInterval() you don't have to take the extra step of having your function recursively call itself. In and of itself it doesn't matter how many seconds you delay it. What matters is what you are actually doing when the function is run. For instance, if you are appending a new element to a global or static array, adding new content to page, etc... each iteration, things are going to add up. Iterating every 1s will give you 60 new elements in 1 minute, vs. 6 new elements, if you are iterating every 10s. Quote Link to comment https://forums.phpfreaks.com/topic/226725-does-setinterval-use-a-lot-of-ramcpu-if-you/#findComment-1170068 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.