Beispiel #1
0
function concurrentExec($cmd)
{
    $chn = make_channel();
    $chnDone = make_channel();
    echo 'Starting ' . FMTWORKERS . '...', PHP_EOL;
    for ($i = 0; $i < FMTWORKERS; ++$i) {
        cofunc(function ($chn, $chnDone, $cmd, $i) {
            while (true) {
                $str = $chn->out();
                if (null === $str) {
                    break;
                }
                passthru(sprintf($cmd, $str) . ' | while read line; do echo "' . ($i + 1) . ' $line"; done');
            }
            $chnDone->in('OK');
        }, $chn, $chnDone, $cmd, $i);
    }
    return [$chn, $chnDone];
}
Beispiel #2
0
function GoogleConcurrentFirst($qry)
{
    $chn = make_channel();
    cofunc(function ($chn, $qry) {
        $chn->in(First($qry, 'Web1', 'Web2', 'Web3'));
    }, $chn, $qry);
    cofunc(function ($chn, $qry) {
        $chn->in(First($qry, 'Image1', 'Image2', 'Image3'));
    }, $chn, $qry);
    cofunc(function ($chn, $qry) {
        $chn->in(First($qry, 'Video1', 'Video2', 'Video3'));
    }, $chn, $qry);
    $results = [];
    for ($i = 0; $i < 3; ++$i) {
        $results[] = $chn->out();
    }
    $chn->close();
    return $results;
}
Beispiel #3
0
                        }
                        $this->appendCode($text);
                    }
                    $this->walkUntil(ST_SEMI_COLON);
                    break;
                default:
                    $this->appendCode($text);
            }
        }
        return $this->code;
    }
}
$suffix =& $opt['suffix'];
$pass = new Build($suffix);
$chn = make_channel();
$chn_done = make_channel();
$workers = 2;
echo 'Starting ', $workers, ' workers...', PHP_EOL;
for ($i = 0; $i < $workers; ++$i) {
    cofunc(function ($pass, $chn, $chn_done) {
        while (true) {
            $target = $chn->out();
            if (empty($target)) {
                break;
            }
            echo $target, PHP_EOL;
            file_put_contents($target . '.php', $pass->format(file_get_contents($target . '.src.php')));
            if (file_exists($target . '.stub.src.php')) {
                file_put_contents($target . '.stub.php', $pass->format(file_get_contents($target . '.stub.src.php')));
            }
        }
Beispiel #4
0
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
include "csp.php";
$chn = make_channel();
cofunc(function ($chn) {
    sleep(5);
    $chn->in('timeout');
}, $chn);
$chn2 = make_channel();
cofunc(function ($chn2) {
    sleep(rand(3, 6));
    $chn2->in('action taken');
}, $chn2);
$chn3 = make_channel();
cofunc(function ($chn3) {
    sleep(4);
    echo 'Got: ', $chn3->out(), PHP_EOL;
}, $chn3);
while (true) {
    select_channel([[$chn, function ($msg) {
        echo "Message Received 1:", print_r($msg, true), PHP_EOL;
        die;
    }], [$chn2, function ($msg) {
        echo "Message Received 2:", print_r($msg, true), PHP_EOL;
    }], [$chn3, 'Hello World', function () {
        echo "Sent HW", PHP_EOL;
    }]]);
}
// $chn->close();