Issues with SSH2 and popen


  • Windows 7 Enterprise (Workstation)
  • WampServer 2.5
  • PHP 5.5.12
  • SSH2 0.12 (


I switched to PHP 5.5.12 and executed SSH in PHP via ssh2_connect() inside a forked thread. This results in the forked operation being unable to recognize the ssh2_connect() function (as if it were undefined). The error I get back is as follows:

Fatal error: Call to undefined function ssh2_connect() in C:\www\practice\php\forked.php on line 3 Call Stack: 0.0000 121416 1. {main}() C:\www\practice\php\forked.php:0


What gives? Below is the code I’m working with (index.php is the file I access in the browser when testing all this)…


$page = 'forked.php';
$handle = popen('start /B C:\wamp2.5\bin\php\php5.5.12\php-win.exe '.$page, 'r');
$read = fread($handle, 2096);
echo $read;



$connection = ssh2_connect('', 22);

I should be able to go to index.php in the browser and see something on there about the connection resource being set but instead, I get the error. Why? Maybe this a known issue or something? I can run ssh2_connect() without any problems when it’s not forked using popen() but as soon as I try to use popen() where ssh2_connect() is in the forked stream, it bombs. I just can’t figure out why…

Any insights into this would be appreciated.

For anyone looking at this, I figured it out: I had to pass along to the CLI fork the path to the php.ini file being used indicated by the -c parameter:

$handle = popen('start /B C:\wamp2.5\bin\php\php5.5.12\php-win.exe -c C:\wamp2.5\bin\php\php5.5.12\phpForApache.ini '.$page, 'r');
1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.