I'm trying to connect to a sftp server with ssh2_php extension in a lavarel proyect. The connection work great in a simple php script but the same code doesn't working when i take it to a controller in a blank laravel project.
This is the code of the controller
<?php
namespace App\Http\Controllers;
use Illuminate\Routing\Controller as BaseController;
class Controller extends BaseController
{
public function test() {
try {
$ssh = ssh2_connect(SFTP_SERVER, 22);
$login = ssh2_auth_password($ssh, SFTP_USER, SFTP_PASS);
$sftp = ssh2_sftp($ssh);
$sftp_fd = intval($sftp);
$filesystem = opendir("ssh2.sftp://$sftp_fd/.");
} catch (\Throwable $e) {
return $e->getMessage();
}
}
}
And here is the error response in postman:
As you can see the catch is not catching the error for some reason.
I'm working with php version 7.2
Any idea?
Thanks in advance