Rev 16 | Rev 24 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 16 | Rev 21 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | <?php |
1 | <?php |
2 | 2 | ||
3 | /* |
3 | /* |
4 | * OID-Info.com API for PHP |
4 | * OID-Info.com API for PHP |
5 | * Copyright 2019-2021 Daniel Marschall, ViaThinkSoft |
5 | * Copyright 2019-2021 Daniel Marschall, ViaThinkSoft |
6 | * Version 2021-05-21 |
6 | * Version 2021-06-19 |
7 | * |
7 | * |
8 | * Licensed under the Apache License, Version 2.0 (the "License"); |
8 | * Licensed under the Apache License, Version 2.0 (the "License"); |
9 | * you may not use this file except in compliance with the License. |
9 | * you may not use this file except in compliance with the License. |
10 | * You may obtain a copy of the License at |
10 | * You may obtain a copy of the License at |
11 | * |
11 | * |
Line 1001... | Line 1001... | ||
1001 | 1001 | ||
1002 | $is_ip = filter_var($host, FILTER_VALIDATE_IP) !== false; |
1002 | $is_ip = filter_var($host, FILTER_VALIDATE_IP) !== false; |
1003 | if (!$is_ip) { |
1003 | if (!$is_ip) { |
1004 | $address = @gethostbyname($host); |
1004 | $address = @gethostbyname($host); |
1005 | if ($address === $host) { |
1005 | if ($address === $host) { |
1006 | echo "gethostbyname() failed.\n"; // TODO: exceptions? (also all "echos" below) |
1006 | $msg = "gethostbyname() failed.\n"; // TODO: exceptions? (also all "echos" below) |
- | 1007 | throw new Exception($msg); |
|
- | 1008 | // echo $msg; |
|
1007 | return false; |
1009 | // return false; |
1008 | } |
1010 | } |
1009 | } else { |
1011 | } else { |
1010 | $address = $host; |
1012 | $address = $host; |
1011 | } |
1013 | } |
1012 | 1014 | ||
1013 | $this->socket = @socket_create(AF_INET, SOCK_STREAM, SOL_TCP); |
1015 | $this->socket = @socket_create(AF_INET, SOCK_STREAM, SOL_TCP); |
1014 | if ($this->socket === false) { |
1016 | if ($this->socket === false) { |
1015 | echo "socket_create() failed: " . socket_strerror(socket_last_error()) . "\n"; |
1017 | $msg = "socket_create() failed: " . socket_strerror(socket_last_error()) . "\n"; |
- | 1018 | throw new Exception($msg); |
|
- | 1019 | // echo $msg; |
|
1016 | return false; |
1020 | // return false; |
1017 | } |
1021 | } |
1018 | $result = @socket_connect($this->socket, $address, $service_port); |
1022 | $result = @socket_connect($this->socket, $address, $service_port); |
1019 | if ($result === false) { |
1023 | if ($result === false) { |
1020 | echo "socket_connect() failed: " . socket_strerror(socket_last_error($this->socket)) . "\n"; |
1024 | $msg = "socket_connect() failed: " . socket_strerror(socket_last_error($this->socket)) . "\n"; |
- | 1025 | throw new Exception($msg); |
|
- | 1026 | // echo $msg; |
|
1021 | return false; |
1027 | // return false; |
1022 | } |
1028 | } |
1023 | 1029 | ||
1024 | $this->connected = true; |
1030 | $this->connected = true; |
1025 | } |
1031 | } |
1026 | 1032 | ||
1027 | protected function spp_reader_avail($oid, $failcount=0) { |
1033 | protected function spp_reader_avail($oid, $failcount=0) { |
1028 | $in = "${oid}\n\0"; // PHP's socket_send() does not send a trailing \n . There needs to be something after the \n ... :( |
1034 | $in = "${oid}\n\0"; // PHP's socket_send() does not send a trailing \n . There needs to be something after the \n ... :( |
1029 | 1035 | ||
1030 | if ($failcount >= self::SPP_MAX_CONNECTION_ATTEMPTS) { |
1036 | if ($failcount >= self::SPP_MAX_CONNECTION_ATTEMPTS) { |
1031 | echo "Query $oid: CONNECTION TO SIMPLE PING PROVIDER FAILED!\n"; |
1037 | $msg = "Query $oid: CONNECTION TO SIMPLE PING PROVIDER FAILED!\n"; |
- | 1038 | throw new Exception($msg); |
|
- | 1039 | // echo $msg; |
|
1032 | return null; |
1040 | // return null; |
1033 | } |
1041 | } |
1034 | 1042 | ||
1035 | if (!$this->connected) { |
1043 | if (!$this->connected) { |
1036 | $this->spp_reader_init(); |
1044 | $this->spp_reader_init(); |
1037 | } |
1045 | } |