Reputation: 712
I'm trying to make a cakephp shell use httpsocket, with ssl.
My "strawman" shell:
App::uses('HttpSocket', 'Network/Http');
class UpdaterShell extends AppShell {
public function main() {
// STRAWMAN
$httpSocket = new HttpSocket();
$results = $httpSocket->post(
'https://accounts.google.com/o/oauth2/token',
'foo=bar'
);
debug($results);
}
}
Now, I don't expect a successful response from Google, since in this simple test I haven't provided the necessary params.
But what I do get is: Error@ unable to find the socket transport "ssl" - did you forget to enable it when you configured php?
I didn't, openssl is enabled, and to prove it, this works:
App::uses('AppController', 'Controller');
App::uses('HttpSocket', 'Network/Http');
class StrawmanController extends AppController {
public function index() {
// STRAWMAN
$httpSocket = new HttpSocket();
$results = $httpSocket->post(
'https://accounts.google.com/o/oauth2/token',
'foo=bar'
);
debug($results);
}
}
(and by works, I mean responds with "invalid_request".)
To summarize: openssl works when I use it through a controller or model, but not through the console.
Does anyone know why, and how I can make it work?
Thanks! A
Upvotes: 1
Views: 944
Reputation: 3165
Building on top of Mark's answer.
$httpSocket = new HttpSocket();
$request = array(
'method' => 'POST',
'uri' => array(
'schema' => 'https',
'host' => 'www.samplewebsite.com',
'path' => 'put/your/path/here'
)
);
$result = $httpSocket->request($request);
check out for openssl *nix
distros
php -r "phpinfo();" | grep ssl
For windows, I guess it's called php_openssl.dll
in php.ini
Upvotes: 1
Reputation: 21743
Console PHP and web PHP usually are not the same. Both have different PHP.ini files, thus resulting in some modules not enabled in CLI which you take for granted via web interface.
Make sure you find the right PHP.ini for CLI and enable the SSL module openssl there, as well.
Upvotes: 2