Title: SSH2 Connect Issues
Tags: php;laravel;ssh
Question: I am using Laravel framework with homestead. (Latest Version) and i am trying to use ssh2_connect. I have installed the extension

```sudo apt install php-ssh2
```

and i have tested that its working

```php -m |grep ssh2
```

i am seeing

```ssh2
```

i am assuming that this is correct but when i try and make a connection i get the following error.

```Call to undefined function App\Http\Controllers\ssh2_connect()
```

This is the code i am executing

``` $connection = ssh2_connect($request-&gt;sever_ip, 2222);
    if (!$connection) die('Connection failed');
```

Would someone point me in the right direction?

Comment: $connection = ssh2_connect($request->sever_ip, 2222);
        if (!$connection) die('Connection failed');

Comment: just updated.!!

Comment: where is the php code?

Comment: Add it in the question, not as a comment.

Here is the accepted answer: Because you are in the namespace of the ```Controllers``` you might need to use:

```$connection = \ssh2_connect($request-&gt;sever_ip, 2222);
if (!$connection) die('Connection failed');
```

Comment for this answer: It should work without backslash. Per the documentation: `For functions and constants, PHP will fall back to global functions or constants if a namespaced function or constant does not exist.` https://secure.php.net/manual/en/language.namespaces.fallback.php It's only for globlal classes that you need the backslash.
Comment for this answer: Yes i think the function is just not loaded properly. Maybe it's setup for the php command line but not Apache.
Comment for this answer: i have fixed it after a `vagrant provision` this seem to get it all working.
Comment for this answer: @this.lau_ I agree with you, however I've seen some weird things related to namespaces. If the above doesn't work it is probably ssh2 isn't loaded by the php (apache restart might be needed here).


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 4, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2017:00:01/16/17', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<php><laravel><ssh>', 'Title': 'SSH2 Connect Issues', 'ViewCount': 1280, 'id': 41679025, 'user_AboutMe': '<p>Just a normal guy that loves coding!</p>\n<p>Laravel is my baby eat sleep rage repeat!</p>\n<pre><code>echo &quot;Hello World&quot;\n</code></pre>\n<p>If you need me then my head will be in my mac coding away!</p>\n<blockquote>\n<p>Smell my Cheese!!!</p>\n</blockquote>\n', 'user_AccountId': 1643320.0, 'user_DisplayName': 'Hayden Sweet', 'user_Reputation': 172.0, 'user_Views': 63.0, 'user_id': 1515369.0}}