diff -urN php-5.0.4.orig/ext/sockets/sockets.c php-5.0.4/ext/sockets/sockets.c
--- php-5.0.4.orig/ext/sockets/sockets.c	2005-02-15 00:44:31.000000000 +0100
+++ php-5.0.4/ext/sockets/sockets.c	2005-04-10 17:32:15.851738072 +0200
@@ -542,6 +542,7 @@
 
 		php_sock = (php_socket*) zend_fetch_resource(element TSRMLS_CC, -1, le_socket_name, NULL, 1, le_socket);
 		if (!php_sock) continue; /* If element is not a resource, skip it */
+		if (php_sock->bsd_socket > FD_SETSIZE) continue; /* must ignore it */
 
 		PHP_SAFE_FD_SET(php_sock->bsd_socket, fds);
 		if (php_sock->bsd_socket > *max_fd) {
diff -urN php-5.0.4.orig/ext/standard/streamsfuncs.c php-5.0.4/ext/standard/streamsfuncs.c
--- php-5.0.4.orig/ext/standard/streamsfuncs.c	2005-01-15 05:51:03.000000000 +0100
+++ php-5.0.4/ext/standard/streamsfuncs.c	2005-04-10 17:34:29.274454736 +0200
@@ -588,6 +588,9 @@
 		 * is not displayed.
 		 * */
 		if (SUCCESS == php_stream_cast(stream, PHP_STREAM_AS_FD_FOR_SELECT | PHP_STREAM_CAST_INTERNAL, (void*)&this_fd, 1) && this_fd >= 0) {
+			if (this_fd > FD_SETSIZE)
+				continue;
+
 			
 			PHP_SAFE_FD_SET(this_fd, fds);
 
