2011-02-04 33 views
0

我對Yii相當陌生,目前正嘗試使用此框架來創建一些PHP Web服務。在嘗試執行Yii網站http://www.yiiframework.com/doc/guide/1.1/en/topics.webservice#declaring-web-service-action上提供的Web服務簡要教程時,我遇到了一些麻煩。也就是說,執行腳本時出現「超過60秒的最大執行時間」致命錯誤。我的猜測是getPrice()方法實際上永遠不會被調用。 我很感激任何有關爲什麼這可能會發生的建議。下面列出了我的index.php文件的內容。 (請注意,Yii gramework已正確安裝,並且正在運行帶有php_soap擴展名的PHP 5.3.0)。執行Yii Web服務演示時出現問題

<?php 

$yii=dirname(__FILE__).'/../yii/framework/yii.php'; 
defined('YII_DEBUG') or define('YII_DEBUG',true); 
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3); 
require_once($yii); 

class StockController extends CController{ 

function __construct(){ 
    parent::__construct($this->id, $this->module); 
} 

public function actions(){ 
    return array(
     'quote'=>array(
      'class'=>'CWebServiceAction', 
     ), 
    ); 
} 

/** 
* @param string the symbol of the stock 
* @return float the stock price 
* @soap 
*/ 
public function getPrice($symbol){ 
    $prices=array('IBM'=>100, 'GOOGLE'=>350); 
    return isset($prices[$symbol])?$prices[$symbol]:0; 
    //...return stock price for $symbol 
} 
} 

$client=new SoapClient('http://localhost/SampleWebService/?r=stock/quote'); 
echo $client->getPrice('GOOGLE'); 
?> 

回答

0

似乎很奇怪,你在聲明中呼籲在index.php入口腳本...我也不知道爲什麼要覆蓋的構造?

我認爲,如果這真的在您的輸入腳本中,您缺少調用創建應用程序,或者Yii::createWebApplication($config)->run();Yii::createConsoleApplication($config)->run();,這取決於您是否將此應用程序作爲Web或控制檯應用程序運行。

你確定應用程序按預期運行沒有SOAP /服務的東西?我會設置一個基本的Hello World應用程序(Web或控制檯),然後嘗試Web服務。

+0

我剛剛遇到了這個,這可能有所幫助:http://rowsandcolumns.blogspot.com/2011/02/yii-web-service-and-php-soap-client.html – thaddeusmt 2011-02-06 15:59:00