
常用软件类: |
|杀毒安全 | |联络聊天 | |网络软件 | |多媒体类 | |系统工具 | |图形图像 | |系统工具 | |应用软件 | |行业软件 |
开发设计类: |
|动画制作 | |图像处理 | |3D设计 | |操作系统 | |站长学院 | |网络相关 | |WEB设计 | |数据库类 | |程序开发 |
百度搜藏|
新浪VIvi|
365key|
Younote|
搜狐 |
博采中心|
你好BLOG|
亿友网摘|
网摘博客|
POCO网摘|
和讯网摘|
| <?php echo "Program starts at ". date('h:i:s') . ".\n"; $timeout=10; $result=array(); $sockets=array(); $convenient_read_block=8192; /* Issue all requests simultaneously; there's no blocking. */ $delay=15; $id=0; while ($delay > 0) { $s=stream_socket_client("phaseit.net:80", $errno, $errstr, $timeout, STREAM_CLIENT_ASYNC_CONNECT|STREAM_CLIENT_CONNECT); if ($s) { $sockets[$id++]=$s; $http_message="GET /demonstration/delay?delay=" . $delay . " HTTP/1.0\r\nHost: phaseit.net\r\n\r\n"; fwrite($s, $http_message); } else { echo "Stream " . $id . " failed to open correctly."; } $delay -= 3; } while (count($sockets)) { $read=$sockets; stream_select($read, $w=null, $e=null, $timeout); if (count($read)) { /* stream_select generally shuffles $read, so we need to compute from which socket(s) we're reading. */ foreach ($read as $r) { $id=array_search($r, $sockets); $data=fread($r, $convenient_read_block); /* A socket is readable either because it has data to read, OR because it's at EOF. */ if (strlen($data) == 0) { echo "Stream " . $id . " closes at " . date('h:i:s') . ".\n"; fclose($r); unset($sockets[$id]); } else { $result[$id] .= $data; } } } else { /* A time-out means that *all* streams have failed to receive a response. */ echo "Time-out!\n"; break; } } ?> |
| Program starts at 02:38:50. Stream 4 closes at 02:38:53. Stream 3 closes at 02:38:56. Stream 2 closes at 02:38:59. Stream 1 closes at 02:39:02. Stream 0 closes at 02:39:05. |
| Starting at Thu Apr 12 15:05:01 UTC 2007. Stopping at Thu Apr 12 15:05:05 UTC 2007. 4 second delay. |
| #!/bin/sh echo "Content-type: text/html <HTML> <HEAD></HEAD> <BODY>" echo "Starting at `date`." RR=`echo $REQUEST_URI | sed -e 's/.*?//'` DELAY=`echo $RR | sed -e 's/delay=//'` sleep $DELAY echo "<br>Stopping at `date`." echo "<br>$DELAY second delay.</body></html>" |
虽然清单 3 的特殊实现特定于 UNIX?,但是本文中几乎所有实现都将很好地应用于 Windows?(尤其是 Windows 98 以后的版本)或 PHP 的 UNIX 安装。特别地,清单 1 可以托管在任意一个操作系统中。因此,Linux? 和 Mac OS X 都是 UNIX 变体,因此这里所有的代码都可以在两者的任意一种中运行。