php - 参数$ tv_sec或$ tv_usec作为参数有什么作用?

标签 php sockets php-5.3 php-socket

我创建了一个简单的套接字php 5.3脚本,其中服务器脚本调用...

socket_select($read_set, $write_set, $exception_set, 2);

...循环中我正在使用非阻塞套接字,并且脚本在Win7机器上运行。

问题:此函数将脚本阻止2秒钟。这意味着第四个参数($ tv_sec)确实导致了此块。

我的问题:$tv_sec$tv_usec有什么区别? $tv_usec是做什么的?

php手册上的Function description:
socket_select(array&$read, array&$write, array&$ex, int $tv_sec[,int $tv_usec=0])

tv_sec: The tv_sec and tv_usec together form the timeout parameter. The timeout is an upper bound on the amount of time elapsed before socket_select() return. tv_sec may be zero , causing socket_select() to return immediately. This is useful for polling. If tv_sec is NULL (no timeout), socket_select() can block indefinitely.

tv_usec: no description

最佳答案

如果希望socket_select()函数在给定的微秒后超时,则使用$ tv_usec参数。例如,如果您希望选择少于1秒后超时,则此功能很有用。

关于php - 参数$ tv_sec或$ tv_usec作为参数有什么作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9792077/

相关文章:

php - 如何在mysql表中获得大于我的最大值的最大值

php - 为什么.php 页面显示为文本?

Java NIO 问题/对 isReadable 工作方式的误解

java - 发送到套接字时 Kotlin java.io.NotSerializedException

php - 如何检测用户上传的文件是否大于 post_max_size?

javascript - 根据第一个下拉值填充第二个下拉列表

php - 在 PHP 上使用 Ratchet 和 WebSockets 进行私有(private)和群聊

也可以充当客户端的Python服务器

php - 一个上传目录中包含 5000 个图像文件的网站会降低加载时​​间吗?

mysql - 管理员 URL '&' 更改为 '&'