src/SimpleSocket.php
public function receive() {
		// read 4 byte length first
		$hdr = '';
		do {
			$read = socket_read($this->socket, 4 - strlen($hdr));
			if ($read === FALSE) {
				throw new SimpleSocketException('Reception failed with: ' . socket_strerror(socket_last_error($this->socket)));
			}
			elseif ($read === '' || $read === NULL) {
				return NULL;
			}
			$hdr .= $read;
		} while (strlen($hdr) < 4);

		list($len) = array_values(unpack("N", $hdr));

		// read the full buffer
		$buffer = '';
		do {
			$read = socket_read($this->socket, $len - strlen($buffer));
			if ($read === FALSE || $read == '') {
				throw new SimpleSocketException('Reception failed with: ' . socket_strerror(socket_last_error($this->socket)));
			}
			elseif ($read == '') {
				return NULL;
			}
			$buffer .= $read;
		} while (strlen($buffer) < $len);

		$data = unserialize($buffer);
		return $data;
	}
public function receive() {
		// read 4 byte length first
		$hdr = '';
		do {
			$read = socket_read($this->socket, 4 - strlen($hdr));
			if ($read === FALSE) {
				throw new SimpleSocketException('Reception failed with: ' . socket_strerror(socket_last_error($this->socket)));
			}
			elseif ($read === '' || $read === NULL) {
				return NULL;
			}
			$hdr .= $read;
		} while (strlen($hdr) < 4);

		list($len) = array_values(unpack("N", $hdr));

		// read the full buffer
		$buffer = '';
		do {
			$read = socket_read($this->socket, $len - strlen($buffer));
			if ($read === FALSE || $read == '') {
				throw new SimpleSocketException('Reception failed with: ' . socket_strerror(socket_last_error($this->socket)));
			}
			elseif ($read == '') {
				return NULL;
			}
			$buffer .= $read;
		} while (strlen($buffer) < $len);

		$data = unserialize($buffer);
		return $data;
	}
Read a data packet from the socket in a predetermined format.
@throws \QXS\WorkerPool\SimpleSocketException in case of an error
@return mixed the data, that has been received