Skip to content

Conversation

@sonarta
Copy link

@sonarta sonarta commented Dec 10, 2025

Problem

When executing a RouterOS script that calls another script (/system/script/run), the response may contain empty data blocks. This causes Undefined array key 0 error at line 377 of Client.php because parseResponse() returns an empty array [].

Solution

  • Replace inefficient double parseResponse() call with single call
  • Use !empty() and isset() checks to properly handle empty array responses
  • Add unit test for empty response edge case

Changes

  • src/Client.php: Fixed rosario() method to handle empty parseResponse result
  • tests/ClientTest.php: Added test_parseResponse_emptyArrayHandling() test

Testing

  • PHP syntax validation passed
  • Unit test added for the edge case

Fixes: #136

sonarta and others added 4 commits December 10, 2025 16:25
…ilFreelancer#136)

- Replace inefficient double parseResponse() call with single call
- Add unit test for empty response edge case

Fixes: EvilFreelancer#136
- Replace socket_get_status() with stream_get_meta_data() for clarity
- Only throw timeout exception when timed_out=true AND no data received
- Add configurable 'throw_timeout_exception' option to disable timeout checks
- Update Laravel config with ROUTEROS_THROW_TIMEOUT_EXCEPTION env var

Tested on PHP 8.4.15 with RouterOS 7.12.1, retrieved 72,788 records successfully.

Fixes: EvilFreelancer#131
- Replace socket_get_status() with stream_get_meta_data() for clarity
- Only throw timeout exception when timed_out=true AND no data received
- Add configurable 'throw_timeout_exception' option to disable timeout checks
- Update Laravel config with ROUTEROS_THROW_TIMEOUT_EXCEPTION env var

Tested on PHP 8.4.15 with RouterOS 7.12.1, retrieved 72,788 records successfully.

Fixes: EvilFreelancer#131
fix: improve PHP 8.4 stream timeout handling (issue EvilFreelancer#131)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Possible bug / edge case

1 participant