于JavaScript 可使用 AJAX 的 async(YAHOO.util.Connect.asyncRequest)来达成, 于 PHP 可以用 CURL 来达成此 Multi-Threading 的效果。
程序(async.php)
以下为引用的内容: |
使用
| 以下为引用的内容: <?php $urls = array('http://example1.com', 'http://example2.com'); print_r(async_get_url($urls)); // [0] => example1, [1] => example2 ?> |
测试
sleep.php # 看时间延长取得的效果
| 以下为引用的内容: <?php sleep(intval($_GET['time'])); echo intval($_GET['time']); ?> |
| 以下为引用的内容: <?php $url_array = array( 'http://example.com/sleep.php?time=5', 'http://example.com/sleep.php?time=10', 'http://example.com/sleep.php?time=7', 'http://example.com/sleep.php?time=5', ); print_r(async_get_url($url_array)); // 总花费时间会是 10 秒, 并印出 [0] => 5, [1] => 10, [2] => 7, [3] => 5 ?> |