[筆記]Laravel 讀取PHP SOAP產生High Charts圖表

延續之前測試,只是將R改由PHP包成SOAP,放置另一站台,供Laravel 使用

若日後有需要可獨立R運算於另一主機,簡單筆記SOAP在PHP寫法

 

架設另一站點,提供SOAP Server,驗証部份的Header還是有點一知半解,需再研究一下

<?php 

//驗證伺服器
if ($_SERVER['PHP_AUTH_USER']!='WDASChartUser' || $_SERVER['PHP_AUTH_PW']!='WDASChartPassword') {  
      header('WWW-Authenticate: Basic realm="MyFramework Realm"');  
      header('HTTP/1.0 401 Unauthorized');  
      exit;  
} 

class MyWDASChart{ 
    public function charts($lavel1,$lavel2,$lavel3) {
        exec("Rscript ". dirname(__FILE__)."\R\Test3.R  " .$lavel1." " . $lavel2. " " .$lavel3, $response);
        $result=json_decode($response[0]);        
        return json_encode($result);
    }
} 
$server_config=array(
                    'uri'=>'WDASChart',
                        );

$charHand = new MyWDASChart;
try
{
    
    $server = new SoapServer(null,$server_config);
    $server->setObject($charHand);
    $server->handle();
    
}
catch ( SoapFault $error) {
    
}


?>

Laravel部份,就只需要改Controler部份,其實這部份應放Services...但反正我測試而己。。。就懶唄

把原本exec("Rscript ".resource_path()."\\R\\Test3.R  80 50 40", $response); 部份改由建立SoapClient

但驗証部份要再研究。。。。整合laravel的驗証才行

其它部份維持原樣,正常Work

    public function List5(Request $request) {

        $client_config = array(
                 'location'=> "http://127.0.0.1:7788/ChartServer.php",
                 'uri'=>"WDASChart",
                 'login'=>"WDASChartUser",
                 'password'=>'WDASChartPassword',
                 'trace'=>true,
                 );
         
        try
        {
            $auth = array('WDASChartUser', 'WDASChartPassword');
            $client = new SoapClient(null, $client_config); 
            
            $header = new SOAPHeader('http://127.0.0.1:7788/ChartServer.php', 'auth', $auth, false, SOAP_ACTOR_NEXT);  
            $client->__setSoapHeaders(array($header));                             
            $result= json_decode($client->charts(90, 65,40)); 
        }
        catch(SoapFault $error)
        {
             dd($error->getMessage());
        }
        unset($client); 
        $data=$result[0];
        
        $linearray=array("level1"=>$result[1],"level2"=>$result[2],"level3"=>$result[3]);
        
        return view($this->localview.'.List5',compact('data','linearray'));
    }   

 

打雜打久了,就變成打雜妹

程式寫久了,就變成老乞丐