function execute_socket( $url_segment, $port, $data, $is_info_log = false ) {
		# SOL_TCP =0 , SOL_UDP = 1
		$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);

		if ($sock === false) {
			$obj = "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n";
			return $obj;
		}

		if (($result = (socket_connect($sock, $url_segment, $port))) === false) {
			$obj = "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($sock)) . "\n";
			return $obj;
		} else {
			socket_write($sock, json_encode($data));
			$obj = socket_read($sock, 1024);
			socket_close($sock);
			
			$log_level = 'error';
			if( $is_info_log ) {
				$log_level = 'info';
			}

			log_message($log_level, 'url:'.$url_segment.', port:'.$port.', data:'. json_encode($data).' result:'.$obj );
			return $obj;
		}
	}

+ Recent posts