Issues with SSH2 and popen

Environment:

  • Windows 7 Enterprise (Workstation)
  • WampServer 2.5
  • PHP 5.5.12
  • SSH2 0.12 (php_ssh2-0.12-5.5-ts-vc11-x86.zip)

Problem:

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)…

index.php:

error_reporting(E_ALL);
$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;
pclose($handle);

 

forked.php:

$connection = ssh2_connect('foobar.whatever.com', 22);
var_dump($connection);

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.