Ok, 

 I know not too many people are familure with my extension so I am going to go
over some stuff that it does do and stuff it doesn't.

The plans i have for this extension are more than just a simple soap/rpc
function calls. I want to build a frame work that people can deploy existing
php objects as SoapObject. Making php a very fast soap application server
having exactly the same functionality as SRM but allowing non php clients
access the objects. In addition to making php-soap a soap application server i
have plans have the frame work be able to handle a cluster of soap application
servers. 

I currently use this exacty technology at work and it works great.
I'll try to walk you thru how exactly it works and how powerfull it is.

//MyClass.php
<?
class MyClass
{
  function MyClass()
  {
   $this->db = connect_to_db();
  }

  function getName()
  {
    return $this->name;
  }

  function setName($name)
  {
    $this->name = $name;
  }
 
  function save()
  {
    $query = "update table blah";
    db_query($query); 
  }

  function load()
  {
    $query = "select * from table";
    $res = db_query($query);
    $this->name = $res['name'];
  }
}
?>

So this is a normal db aware object written in php (it obviously doesn't work
but you get the idea).

//somescript.php
<?
include("MyClass.php");
$person = new MyClass();
$person->load();
$person->setName("brad");
$person->save();
?>

Now again.. this script doesn't make much sence alone but make a gui use the
object and it works good.


Ok now we have our class and a php script to use it. 

Now we want to make MyClass a SoapObject. Using php-soap

//MyClassServer.php
<?
include("MyClass.php");
$server = new SoapServer("urn:someservice");
$server->setClass("MyClass");
$server->setPersistence(SOAP_PERSISTENCE_SESSION);
$server->handle();
?>

so one file and 5 lines of code turns MyClass into a SoapObject...
all methods are exposed from MyClass and the
setPersistence(SOAP_PERSISTENCE_SESSION) tells php-soap-server to use php's
session handling to persist the object.

Ok now we write our soap client.
// MyClassClient.php
<?
$person = SoapObject("http://localhost/MyClassServer.php";);
$person->load();
$person->setName("brad");
$person->save();
?>

now as you can see you use the object EXACTLY the same as a soap object as you
use it a local object. Since the server was set up to persist the object each
subsequent call to the same soap object sends the php session id back to the
server the server will restore the session (the created object) and invoke the
next method on the object.

Now i wrote the client in php just for an example but any soap client can use
that php object like a normal object. As long as it will pass the session id
back to the server on each request. 

So basically you have a soap enabled php object that you can run remotely. This
is a generic soultion to j2ee or SRM and a simpler, faster soultion to .net.

Since php soap is using php's session handling you can totally control where
the objects go. I also am currently working two different session handlers one
mod_remote that allows you to grab session info from a remote php server. Kinda
like msession works but a more generic way. You can configure the php session
server to use mod_mm or mod_files or mod_user but still allowing a remote
session server to access its session info. 

Another session handler will allow you to replicate session information.
What this will allow you to do is cluster your phpsoap object servers
replicating all session information to other servers so incase the server that
the object got created on goes down or if the next request got load ballaced to
a different machine the object can still be used.

using thoes two together you can create a realy nice redudent clustered soap
service.

 I will have more on that setup and how it works when i acually get done with
it.


Ok now here is how i use it at work (along with the clustering).
We will be using java for our frontends to our databases. We are going to
deploy these java applications to end users now we obvisouly don't want to open
up our database up to the world let alone use JDBC!. So i created a bunch of
data access objects written in php so im using native dabase calls. Soap
Enabled them with php soap. Build a java gui using a soap client and there you
go a database application. But the best part is if i want to create a MFC
application or a VB application i don't need to rewrite my php database
objects. So if we deploy our frontends to end users all we have to open up is a
simple webserver on port 80.



Now i currently am trying to implement alot of features in php-soap to allow
script writers to override the functionality of the core engine.  Here is an
example.

php-soap encodes hashtable with the apache namespace and that defines a
hashtable to be encoded as follows.

<item>
  <key>some_key</key>
  <value>some_value</value>
</item>
<item>
  <key>some_key2</key>
  <value>some_value2</value>
</item>

now i just found out that M$ decited to encode their hashtables differntly.
So they encode them as follows

<keys>
 <key>some_key</key>
 <key>some_key2</key>
</keys>
<values>
 <value>some_value</value>
 <value>some_value2</value>
</values>

So obviosuly php-soap won't be able to interop with .net's hashtables. 
(I think they way they encode it is a crock of **** but hey they make all the
money)


so I am currently building a way that you can do something like this

<?
$server = new SoapServer("urn:hash");
$server->addFunction("return_hash");
if($_SERVER['NotSureWhatHeader'] == ".NET")
{
  $server->map("apache:Map", null, "dot_net_hash");
}
$server->handle();

//evertime php soap finds a hashtable it will call this function for encoding
function dot_net_hash($zval)
{
 $map = new DomElement("return");
 $keys = new DomElement("keys");
 $values = new DomElement("values");
        
 foreach(array_keys($zval) as $skey)
 {
  $key = new DomElement("key");
  $key->set_content($skey);
  $keys->append_child($key);
 }
        
 foreach($zval as $data)
 {
  $values->append_child(soap_encode_to_xml("value", $data));
 }

 $map->append_child($keys);
 $map->append_child($values);
 return $map;
}
?>

So with that example evertime a dotnet client hits the server it will spit out
a .net hashtable and other clients will get a apache hashtable.

To get that to work i need to change the domxml extension.

So now all interop issues can be solved in userland.


The other big issue is transport layer. Currently i only have implemented http.
But i do plan on giving the user full control of the transport layer in
addition to trying to re-use some of wes's stream stuff to supply some other
forms of transport.

You can also return custom soapfaults.

This doesn't even touch what php-soap will do when it is bound to a wsdl. There
is some fancy stuff it does. 

here is a link if you want to read a little about it.
http://www.geocrawler.com/lists/3/SourceForge/21431/0/8578899/


here is another link about benchmarks that were done on php-soap
http://sourceforge.net/mailarchive/forum.php?thread_id=690533&forum_id=8701


- Brad

__________________________________________________
Do You Yahoo!?
LAUNCH - Your Yahoo! Music Experience
http://launch.yahoo.com

-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to