Example #1
0
                $response->setData(file_get_contents($response->url));
                $response->setFinish(microtime(true));
            }
        }
    }
}
/*
* We can retain the reference to the response object !!
*/
$response = new Response(sprintf("http://www.google.com/?q=%s", md5(rand() * time())));
/*
* Initialize a new threaded request with a response object as the only parameter
*/
$request = new Request($response);
/*
* Tell you all about it ...
*/
printf("Fetching: %s ", $response->getUrl());
if ($request->start()) {
    /* do something during runtime */
    while ($request->isRunning()) {
        echo ".";
        usleep(100);
    }
    /* 
    	you do not need to join:
    		when a thread returns false for isRunning then your code is no longer being executed
    		pthreads will cleanup the variable when it goes out of scope like any other variable in php
    */
    printf(" got %d bytes in %f seconds\n", $response->getLength(), $response->getDuration());
}