2013-03-19 81 views
1

我正在嘗試使用SSLL做一個cakephp shell使用httpsocket和ssl。Cakephp httpsocket ssl不能與控制檯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); 
} 
} 

現在,我不希望從谷歌的成功響應,因爲在這種簡單的測試,我還沒有提供必要的PARAMS。

但我做什麼得到的是:[email protected] unable to find the socket transport "ssl" - did you forget to enable it when you configured php?

我沒有,OpenSSL是啓用的,爲了證明這一點,這個工程:

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); 
} 
} 

(和作品,我的意思是響應與「invalid_request」。)

總結:當我通過控制器或模型,而不是通過控制檯使用它openssl的作品。

有誰知道爲什麼,以及如何讓它工作?

謝謝! A

+0

PS:既很好地工作正常稱職的http:// – 2013-03-19 11:28:50

回答

2

控制檯PHP和網頁PHP通常是不一樣的。 兩者都有不同的PHP.ini文件,從而導致某些模塊在CLI中未啓用,您通過Web界面將其視爲理所當然。

確保找到適合CLI的PHP.ini,並在那裏啓用SSL模塊openssl。

+0

正確的!一旦我知道要尋找什麼,'php --ini'告訴我,在這檯筆記本電腦上有第三個我忘記了的php.ini文件,並沒有openll。請注意:在同一臺計算機上安裝xampp和wamp需要您自擔風險,並且只有在您獲得付款後才能這樣做! – 2013-03-19 12:50:55

1

建立在Mark的答案之上。

$httpSocket = new HttpSocket(); 
$request = array(
     'method' => 'POST', 
     'uri' => array(
        'schema' => 'https', 
        'host' => 'www.samplewebsite.com', 
        'path' => 'put/your/path/here' 
        ) 
    ); 
$result = $httpSocket->request($request); 

退房OpenSSL的*nix發行版

php -r "phpinfo();" | grep ssl 

對於Windows,我想這就是所謂的php_openssl.dllphp.ini