-
-
Notifications
You must be signed in to change notification settings - Fork 145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error reading 1 bytes #68
Comments
Hello! I'm not sure if this is a problem with this library, the RouterOS API is a very fragile thing in itself. My opinion is that you see this error because the size of the buffer allocated for processing API requests was exceeded, I am sure that if you try to repeat this procedure (thousands of concurrent requests) using any other library, you will get a similar error. Check the RouterOS logs first, probably answer will be here at the moment when this error occurs. |
Another reason is that the API made a mistake and tries to send request data N-1 to request N, but request N-1 has already received it and therefore the API does not know what to do and spits out an error. By the way, I am very surprised that you found the way to make many parallel requests to the RouterOS API, usually this is a big headache :) Especially if you need a valid data from the RouterOS (not only creating/updating/deleting of something, because these three returns nothing). |
Hello, |
Hello @matracine it's a good idea! I guess for the first need to reproduce this error via tests and add exception. You did the part about working with streams, perhaps it would be better if you implement this exception :) If you have spare time of course. |
@EvilFreelancer After testing, I found that if I request the API from different IPs at the same time, this problem will not occur. If I request multiple requests at the same time on a single IP, the problem will occur. |
You probably mean source ip? Nope, library does not support this. |
I mean, for example, if there are 192.168.1.2~5 in the vm, can you specify one of them to access ros? |
This library is just a converter of API commands from human-readable format to format which API server may understand, and that's all. So if you need something more, than it should be implemented from your side :) |
For example curl's CURLOPT_INTERFACE |
The RouterOS API is not an ordinary HTTP API (RESTful/SOAP/GraphQL/etc.), it's TCP-based, with a non-typical format of requests and responses, with bitwise shifting. Communication between the API server takes place using the stream extensions, options can be passed via stream_context_create method. And as i know in raw TCP mode not possible to use proxy. Ah, btw, curl flags is also not possible to use. |
@EvilFreelancer : https://www.php.net/manual/en/context.socket.php, parameter "bindto".... |
@matracine thanks, I did not know about this solution. Need to add this useful option to one of future releases. |
@wartw so as temporary solution you may add bindto to array with stream context options, and in some of future releases it will be implemented in normal way (via Config parameter I mean) |
I will try tomorrow |
@wartw hello! A |
Not tested yet, it's busy these days |
Okay, please ping me if it works, i'll add support of this parameter to the library then. |
Hello! I've added support of https://github.com/EvilFreelancer/routeros-api-php#list-of-available-configuration-parameters It's easy to use: $client = new Client([
'socket_options' => [
'bindto' => '192.168.1.10:7000'
]
]); Already available in version 1.4.3 |
I forgot to tell you, it works |
Very good operation (processing tens of thousands of different records at the same time, there will be no abnormalities |
This error often occurs when there are more than tens of thousands of concurrent requests
Fatal error: Uncaught RouterOS\Exceptions\StreamException: Error reading 1 bytes in /www/wwwroot/e5218129d40e2b46.sn.mynetname.net/routeros-api-php/src/Streams/ResourceStream.php:59 Stack trace: #0 /www/wwwroot/e5218129d40e2b46.sn.mynetname.net/routeros-api-php/src/APILengthCoDec.php(115): RouterOS\Streams\ResourceStream->read() #1 /www/wwwroot/e5218129d40e2b46.sn.mynetname.net/routeros-api-php/src/APIConnector.php(53): RouterOS\APILengthCoDec::decodeLength() #2 /www/wwwroot/e5218129d40e2b46.sn.mynetname.net/routeros-api-php/src/Client.php(255): RouterOS\APIConnector->readWord() #3 /www/wwwroot/e5218129d40e2b46.sn.mynetname.net/routeros-api-php/src/Client.php(310): RouterOS\Client->readRAW() #4 /www/wwwroot/e5218129d40e2b46.sn.mynetname.net/routeros-api-php/src/Client.php(481): RouterOS\Client->read() #5 /www/wwwroot/e5218129d40e2b46.sn.mynetname.net/routeros-api-php/src/Client.php(538): RouterOS\Client->login() #6 /www/wwwroot/e5218129d40e2b46.sn.mynetname.net/routeros-api-php/src/Client.php(88): RouterOS\Client->connect in /www/wwwroot/e5218129d40e2b46.sn.mynetname.net/routeros-api-php/src/Streams/ResourceStream.php on line 59
The text was updated successfully, but these errors were encountered: