src/SimpleSocket.php
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;
	}
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;
	}
Selects active sockets with a timeout
@param SimpleSocket[] $readSockets Array of \QXS\WorkerPool\SimpleSocket Objects, that should be monitored for read activity
@param SimpleSocket[] $writeSockets Array of \QXS\WorkerPool\SimpleSocket Objects, that should be monitored for write activity
@param SimpleSocket[] $exceptSockets Array of \QXS\WorkerPool\SimpleSocket Objects, that should be monitored for except activity
@param int $sec seconds to wait until a timeout is reached
@param int $usec microseconds to wait a timeout is reached
@return array Associative Array of \QXS\WorkerPool\SimpleSocket Objects, that matched the monitoring, with the following keys 'read', 'write', 'except'