Trying to use popen w/ ssh2_connect and having problems...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Wolf_22
Forum Contributor
Posts: 159
Joined: Fri Dec 26, 2008 9:43 pm

Trying to use popen w/ ssh2_connect and having problems...

Post by Wolf_22 »

Long story short, I've used open() to fork processing. The new thread uses another PHP file that calls ssh2_connect(). I'm not sure what's happening but it's not working and claims that ssh2_connect() is undefined.

Here's what's in index.php:

Code: Select all

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);
And here's what's in "forked.php":

Code: Select all

$connection = ssh2_connect('foobar.whatever.com', 22);
var_dump($connection);
Is there something wrong with php-win.exe being unable to use certain PHP functions when done using something like popen()? This worked when I used PHP 5.3 (or at least, I remember it working) but when I switched over to PHP 5.5.12, it just doesn't. The really strange thing is that calling ssh2_connect() from the main thread (not forking it) works without a single problem.

Any help with this would be appreciated.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Trying to use popen w/ ssh2_connect and having problems.

Post by requinix »

WAMP will be using one configuration for PHP, while calling it from the command-line will use a different configuration (the default).

Find the configuration file and use PHP's -c flag to tell it to load that configuration.

Code: Select all

...\php-win.exe -c C:\wamp2.5\path\to\php.ini $page
Wolf_22
Forum Contributor
Posts: 159
Joined: Fri Dec 26, 2008 9:43 pm

Re: Trying to use popen w/ ssh2_connect and having problems.

Post by Wolf_22 »

Man, I could kiss you right now. That was it!

Seriously, thanks. You have no idea how much of a headache that had been causing me.
Post Reply