Giancarlo Sanchez
Giancarlo Sanchez

Reputation: 207

Handling a Webservice stream in PHP

Good day guys.

I need to consume a webservice that works as a file streaming (it receives a file Id and returns the file via stream).

Then in PHP I must handle this process. I have been looking for a solution on how to do this since, as far as I know, the native soap client in PHP does not have these capabilities.

I found WSO2 (Web Services Framework for PHP) which handles Binary attachment ( MTOM ).

I'm yet to test it, but the real question is, based on your experience, what would be the smartest approach for consuming a webservice with these characteristics?

Thank you very much for your time.

Upvotes: 1

Views: 1203

Answers (1)

Baba
Baba

Reputation: 95151

WSO2 WSF/PHP is a better more sophisticated of doing file streaming using MTOM which is a standard that other languages support.

MTOM uses base64 to encode files which you can implement on your on if you don't want yo use WSO2

Am not sure why you want stream please note that you can always open any file asstream so far you have a copy of that files so i don't think that is the most important .. what is key is sending the file safely to the server

Example using SoapClient

Client

ini_set("soap.wsdl_cache_enabled", "0");
$client=new SoapClient(PATH_TO_WSDL,array('encoding'=>'ISO-8859-1'));
$data = file_get_contents(PATH_TO_FILE);
$ret = $client->recieveFile(base64_encode($data));

Server

ini_set("soap.wsdl_cache_enabled", "0");

const  PATH_TO_WSDL = "b.php?wsdl" ;
$client=new SoapClient(PATH_TO_WSDL,array('encoding'=>'ISO-8859-1'));
$data = file_get_contents(PATH_TO_FILE);
$ret = $client->recieveFile(base64_encode($data));

Please note that base64 would increase the file by 33% it advisable to spit the files into chunks for very large files

Upvotes: 2

Related Questions