notuo
notuo

Reputation: 1161

How to throttle a loop in php

I have to process a script that consumes a lot of CPU and this is for a bunch of users and depends on the user, so I want to run it once, wait for few seconds, run the next user, etc.

I tried delay but the issue I got is that I never get anything printed in the screen to get info about how the whole process is doing and to get intermediate results.

I have one script in which I plan to do this and then run the other process.

Any hints?

Upvotes: 0

Views: 662

Answers (2)

Tero Lahtinen
Tero Lahtinen

Reputation: 524

There is a POSIX compatible ptreads package, which may be useful here. See https://github.com/krakjoe/pthreads

Upvotes: 0

kguest
kguest

Reputation: 3844

You could base what you need on this:

for ($i; $i < 10; $i++) {
    do_something();
    sleep(1); // sleep for a second.
}

Upvotes: 1

Related Questions