可以看到,如果是PHP_NORMAL_READ模式,其实行为和socket_recv是一样的,都是用的系统的recv函数,但是如果是PHP_NORMAL_READ,则有很大区别,用了自己实现的php_read函数,那这个php_read是干啥的呢?我们继续看源码: 复制代码 代码如下: *t = " "; while (*t != "
" && *t != "
" && n < maxlen) { if (m > 0) { t++; n++; } else if (m == 0) { no_read++; if (nonblock && no_read >= 2) { return n; /* The first pass, m always is 0, so no_read becomes 1 * in the first pass. no_read becomes 2 in the second pass, * and if this is nonblocking, we should return.. */ } if (no_read > 200) { set_errno(ECONNRESET); return -1; } } if (n < maxlen) { m = recv(sock->bsd_socket, (void *) t, 1, flags); } if (errno != 0 && errno != ESPIPE && errno != EAGAIN) { return -1; } set_errno(0); }