pear2/Net_RouterOS

PEAR2\Net\Transmitter\SocketException: Failed to connect with socket.

brsnik opened this issue · 3 comments

I attempted to connect, however I get this error. Is it a php socket problem?

What is my next step in solving this? We are running a Debian server, where the script is located.

PEAR2\Net\Transmitter\SocketException: Failed to connect with socket. in /home/admin/web/domain/public_html/PEAR2/Net/Transmitter/TcpClient.php:199 Stack trace: #0 /home/admin/web/domain/public_html/PEAR2/Net/Transmitter/TcpClient.php(160): PEAR2\Net\Transmitter\TcpClient->createException('Failed to conne...', 8) #1 /home/admin/web/domain/public_html/PEAR2/Net/RouterOS/Communicator.php(141): PEAR2\Net\Transmitter\TcpClient->__construct('xx.29.xx.xx', 8728, false, '60', 'uniroyal%2Funir...', '', Resource id #1) #2 /home/admin/web/domain/public_html/PEAR2/Net/RouterOS/Client.php(139): PEAR2\Net\RouterOS\Communicator->__construct('xx.29.xx.xx', 8728, false, NULL, 'uniroyal/uniroy...', '', NULL) #3 /home/admin/web/domain/public_html/mtk_api.php(18): PEAR2\Net\RouterOS\Client->__construct('xx.29.xx.xx', 'uniroyal', 'uniroyal') #4 {main} Next PEAR2\Net\RouterOS\SocketException: Error connecting to RouterOS in /home/admin/web/domain/public_html/PEAR2/Net/RouterOS/Communicator.php:151 Stack trace: #0 /home/admin/web/domain/public_html/PEAR2/Net/RouterOS/Client.php(139): PEAR2\Net\RouterOS\Communicator->__construct('xx.29.xx.xx', 8728, false, NULL, 'uniroyal/uniroy...', '', NULL) #1 /home/admin/web/domain/public_html/mtk_api.php(18): PEAR2\Net\RouterOS\Client->__construct('xx.29.xx.xx', 'uniroyal', 'uniroyal') #2 {main}

That error typically appears when PHP is not whitelisted in the OS' firewall.
(more precisely, not allowed to make outgoing connections)

I'm not entirely sure how you whitelist a binary under Debian... Probably using SELinux?

If PHP is running as an Apache module:

 setsebool -P httpd_can_network_connect 1 

And... I have no idea how if it's running as FCGI. If that's the problem, and you find out exactly how to whitelist the FCGI binary with SELinux, I'll appreciate it if you share the command for it, so that I can include it in the wiki.

We fixed it. It was a firewall setting. We are on php7, should we expect any problems?

Also we have another question I'll post about shortly..

Was it the setting I suggested above or something else? Could you share what you changed please?

I'm not aware of any PHP 7 specific issues. If you find any, you'll be the first to report such.

There's an issue with streams in later PHP 5.6 releases that is also inherently in PHP 7, but you're not going to encounter that unless you use charset conversion (which uses streams under the hood) or if you use actual seekable streams instead of strings.

If you REALLY need those, the "develop" branch in Net_Transmitter has that fixed already, though I'd not recommend mixing versions like that.