コード例 #1
0
ファイル: example05.php プロジェクト: razielox/php_threading
function progress($ch)
{
    // infinite loop
    for (;;) {
        echo "still downloadin'...\n";
        // the second argument to thread_message_queue_poll is a timeout
        // if it times out, it returns the string (not the constant) PHP_THREAD_POLL_TIMEOUT
        // this function is blocking (it waits until a message is recieved or timeout triggered)
        $var = thread_message_queue_poll($ch, 500);
        if ($var == 'done') {
            return;
        }
    }
}
コード例 #2
0
ファイル: example04.php プロジェクト: razielox/php_threading
function sub($i, $ch)
{
    for (;;) {
        // receive the message from $ch
        $a = thread_message_queue_poll($ch);
        // TRIPLE COMPARISION IS IMPORTANT!!!!
        if ($a === 'PHP_THREAD_POLL_STOP') {
            break;
        }
        printf("thread %02d: %02s\n", $i, $a * 2);
    }
    sleep(2);
    printf("thread %02s is done.\n", $i);
}