News:

Wondering if this will always be free?  See why free is better.

Main Menu

How does pasttime work?

Started by wing, July 29, 2005, 07:19:49 PM

Previous topic - Next topic

wing

Just wondering how this pasttime works.

It looks like it gets called after every action (well most actions) if past them time, refresh the page and continue from where it left off.

What's got me confused is, I get into say step 7 and I do a foreach loop, I don't call pasttime during the foreach loop, yet it will pause it and when it comes back it's screwed.


[Unknown]

Well, you give pastTime() a number, and it restarts using that number.  If you foreach, just do something to spin away the bad data, or use a for instead.

The idea is to prevent timeouts, and to go easy on the webserver (because copying data is taxing for servers.)

-[Unknown]

wing

But if I don't call pastTime it shouldn't restart should it?  See that's what's confusing.

I do a foreach to get all my posts, and it magically restarts, and then says the foreach value is not valid.  ???

I would actually like to pause, not sure how I can do that in the middle of my foreach though. 

I think the REQUEST[start] variable is the confusing part.  When the pastTime function evaluates to true, it calls the script again, passing the current step back and something about request start.

It looks like then at the start of the function the clearing statements are surrounded by if start = 0 then run them, if not just skip over them.  But what do I do with my foreach?  I want to come back in it but half way through.

[Unknown]

Quote from: wing on July 29, 2005, 08:08:20 PM
But if I don't call pastTime it shouldn't restart should it?  See that's what's confusing.

If you don't call it, it won't restart it... but, if it's called later, it may restart it - and if you still do the foreach without checking that number, you'll do it twice.

QuoteIt looks like then at the start of the function the clearing statements are surrounded by if start = 0 then run them, if not just skip over them.  But what do I do with my foreach?  I want to come back in it but half way through.

Well, I would do something like this, if you need a foreach:

$x = 0;
foreach ($array as $value)
{
   if ($x++ < $_REQUEST['start'])
      continue;

   // ... code here...
}

-[Unknown]

wing

Thank Unknown.  I think that fixed my problems.

I had to re-write some of the stuff to slow down the processing, that + this little snippet of code and I think it's ready for prime time.

wing

Geez processor load is still high in a foreach loop.... no way to minimize that eh?

wing

Unknown, I have attached my messy script.

When it gets to line 878 it processes for awhile LONG LONG while at full bore, but it does seem to call pastTime but then fails :(

Snap, I can't attach it?

[Unknown]

If you email it to me ([email protected]) I can attach it.

-[Unknown]

wing

Done, there's a bug in that, I was missing the { } at line 870 & 874

Advertisement: