Skip to content
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

try catch #69

Closed
Tahernejad opened this issue Oct 13, 2021 · 6 comments
Closed

try catch #69

Tahernejad opened this issue Oct 13, 2021 · 6 comments
Assignees
Labels
question Further information is requested

Comments

@Tahernejad
Copy link

Hello,
How can detect connection or login is successful or not ?
Please help me with example,
Thanks a lot.

@Tahernejad Tahernejad added the question Further information is requested label Oct 13, 2021
@Tahernejad
Copy link
Author

try { $client = new Client([ 'host' => IP_ADDRESS, 'user' => USER, 'pass' => PASS, 'port' => 8728 ]); } catch (\Exception $e) { var_dump($e); }

In this case

stream_set_blocking(): Argument #1 ($stream) must be of type resource, bool given

I add 'socket_blocking' => false

stream_set_timeout(): Argument #1 ($stream) must be of type resource, bool given

I add 'socket_timeout' => 10

stream_set_timeout(): Argument #1 ($stream) must be of type resource, bool given

@EvilFreelancer
Copy link
Owner

EvilFreelancer commented Oct 14, 2021

Hello! Interesting question, it should be already implemented in exceptions.

This stream_set_blocking(): Argument #1 ($stream) must be of type resource, bool given mean there is no stream instantiated.

I'll check why exception was not triggered before.

@Tahernejad
Copy link
Author

Thanks,
Other question:
I use catch (\Exception $e)
I want use $e->message but it's protected
Can you help me ?

@EvilFreelancer
Copy link
Owner

Hello! Try to use this https://www.php.net/manual/ru/exception.getmessage.php

@EvilFreelancer
Copy link
Owner

Hello! I've added additional check for stream resource, available in 1.4.3
https://github.com/EvilFreelancer/routeros-api-php/blob/master/src/SocketTrait.php#L57

@Tahernejad
Copy link
Author

Thank you very much ❤

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants