Installing wsf/php in a third party hosting environment

Wednesday, August 6, 2008

If you have a third party hosting environment and you want to use wsf/php extension, you have to set to deploy the PHP as cgi-based and not through traditional mod_php. That way you will be able to use custom php.ini and configure wsf/php installation. Make sure to check whether your hosting service have capability to deploy cgi-based php and any documentation for that. For an example dreamhost provides following documentation for that. http://wiki.dreamhost.com/Custom_PHP.ini

There may be some hosting environments (Here I mean hosting services deployed php in linux based systems) that you are not have permission to read root directories. So in such cases you have to set the extension_dir entry in the php.ini relative to the cgi-bin directory in your document root. But wsf/php 1.3.2 and lower versions having a problem of not loading wsf.home directory when you are using WSClient class. But it works well for WSService by default.

You can solve this problem by putting the following code right before you use WSClient.

$script_dir = dirname($_SERVER['PHP_SELF']);
$htdocs_dir = '.'.preg_replace('/[^\\/']+/, '..', $script_dir);
$cgibin_dir = $htdocs_dir.'/cgi-bin';


chdir($cgibin_dir);



For an example if you put the above code to the echo client in sample directory it would be like,


$requestPayloadString = <<<XML
<ns1:echoString xmlns:ns1=http://php.axis2.org/samples><text>Hello World!</text></ns1:echoString>

XML;

try {


$script_dir = dirname($_SERVER[
"PHP_SELF"]);
$htdocs_dir =
".".preg_replace("/[^\\/"]+/, "..", $script_dir);
$cgibin_dir = $htdocs_dir.
"/cgi-bin";


chdir($cgibin_dir);

$client = new WSClient(array( to =>
"http://test.dimuthu.org/samples/echo_service.php" ));


$responseMessage = $client->request( $requestPayloadString );

printf(Response =
"%s <br>", htmlspecialchars($responseMessage->str));


} catch (Exception $e) {

if ($e instanceof WSFault) {

printf(Soap Fault:
"%s\\n", $e->Reason);
} else {
printf(Message = "%s\\n
",$e->getMessage());
}


}
?>

2 comments:

Ishwinder said...

Hello,

Is it possible to install the wsf on shared host? I dont find its possible because pecl tries to build in the directory /var/tmp which we dont have access to on shared host. Can you please comment?

Thanks.

Dimuthu said...

Hi ishwinder,
Please check my blog on http://www.dimuthu.org/blog/2008/08/16/install-php-wsfphp-and-dataservices-in-a-shared-hosting-environment/. There I have build wsf/php from source. I have not tried with pecl, but if need /var/tmp write access we can't do it with pecl.
Thanks
Dimuthu