public static function select(array $readSockets = array(), array $writeSockets = array(), array $exceptSockets = array(), $sec = 0, $usec = 0) {
		$out = array();
		$out['read'] = array();
		$out['write'] = array();
		$out['except'] = array();

		if(count($readSockets) === 0){
			return $out;
		}

		$readSocketsResources = array();
		$writeSocketsResources = array();
		$exceptSocketsResources = array();
		$readSockets = self::createSocketsIndex($readSockets, $readSocketsResources);
		$writeSockets = self::createSocketsIndex($writeSockets, $writeSocketsResources);
		$exceptSockets = self::createSocketsIndex($exceptSockets, $exceptSocketsResources);

		$socketsSelected = @socket_select($readSocketsResources, $writeSocketsResources, $exceptSocketsResources, $sec, $usec);
		if ($socketsSelected === FALSE) {
			$socketError = socket_last_error();
			// 1 more retry https://stackoverflow.com/questions/2933343/php-can-pcntl-alarm-and-socket-select-peacefully-exist-in-the-same-thread/2938156#2938156
			if ($socketError === SOCKET_EINTR) {
				socket_clear_error();

				$socketsSelected = socket_select($readSocketsResources, $writeSocketsResources, $exceptSocketsResources, $sec, $usec);
				if ($socketsSelected === FALSE) {
					return $out;
				}
			} else {
				trigger_error(
					sprintf('socket_select(): unable to select [%d]: %s', $socketError, socket_strerror($socketError)),
					E_USER_WARNING
				);
				return $out;
			}
		}

		foreach ($readSocketsResources as $socketResource) {
			$out['read'][] = $readSockets[intval($socketResource)];
		}
		foreach ($writeSocketsResources as $socketResource) {
			$out['write'][] = $writeSockets[intval($socketResource)];
		}
		foreach ($exceptSocketsResources as $socketResource) {
			$out['except'][] = $exceptSockets[intval($socketResource)];
		}

		return $out;
	}