Subject: | Memory leak when calling WS using wsdl |
There appears to be a slow memory leak when using a .wsdl file to make SOAP calls. Sample
code attached. The attached script grew from ~11MB at start to ~20MB RES size (VIRT went from
14MB to ~24MB) after running ~40,000 query loops. Confirmed this under both Ubuntu 6.06
LTS (perl 5.8.7) and Debian 4.0 STABLE (perl 5.8.8) with SOAP::Lite 0.71.07 installed from CPAN.
Attached code is .pl file, .wsdl, as well as a PHP-based server which runs from the same .wsdl.
Subject: | auth_mem_leak_test.pl |
#!/usr/bin/perl -w
use strict;
use SOAP::Lite;
#use SOAP::Lite +trace => [qw (debug)];
use Data::Dumper;
# .NET compatibility configuration per SOAP::Lite manpage
$SOAP::Constants::DO_NOT_USE_CHARSET = 1;
my $xmlns = 'http://foo.com/webservices/';
my $endpoint = 'http://localhost/Authentication_test.php';
my $strAccount = 'foo';
my $strReferrer = 'unknown';
my $strSourceURL = 'http://bar.com/test/object.jpg';
my $strClientIP = '1.2.3.4';
my $query_count = 1;
while (1) {
my $strToken = int(rand(10000));
my $soap = SOAP::Lite->service('file://var/www/Auth.wsdl')
#->proxy($endpoint)
->ns('http://foo.com/webservices', 'tns');
$soap->on_fault(\&handle_fault);
print "Sending token $strToken: ";
my $result = $soap->Authenticate($strAccount, $strToken, $strReferrer, $strSourceURL, $strClientIP);
if ($result) {
print "Query $query_count: Authentication passed!\n";
} else {
print "Query $query_count: Authentication failed.\n";
}
$query_count++;
}
sub handle_fault {
my ($soap, $res) = @_;
my $err = $soap->transport->status;
print "SOAP Transport error: $err\n";
}
Subject: | Auth.wsdl |
<?xml version="1.0" ?>
<definitions name="Authentication" targetNamespace="http://foo.com/webservices" xmlns:typens="http://foo.com/webservices" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/">
<types>
<xsd:schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://foo.com/webservices">
</xsd:schema>
</types>
<message name="doAuthenticate">
<part name="strAccount" type="xsd:string" />
<part name="strToken" type="xsd:string" />
<part name="strReferrer" type="xsd:string" />
<part name="strSourceURL" type="xsd:string" />
<part name="strClientIP" type="xsd:string" />
</message>
<message name="doAuthenticateResponse">
<part name="Result" type="xsd:int" />
</message>
<portType name="AuthenticationPort">
<operation name="Authenticate">
<input message="typens:doAuthenticate" />
<output message="typens:doAuthenticateResponse" />
</operation>
</portType>
<binding name="AuthenticationBinding" type="typens:AuthenticationPort">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
<operation name="Authenticate">
<soap:operation soapAction="http://foo.com/webservices/Authenticate" />
<input>
<soap:body use="encoded" namespace="http://foo.com/webservices" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</input>
<output>
<soap:body use="encoded" namespace="http://foo.com/webservices" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</output>
</operation>
</binding>
<service name="AuthenticationService">
<port name="AuthenticationPort" binding="typens:AuthenticationBinding">
<soap:address location="http://localhost/Authentication_test.php" />
</port>
</service>
</definitions>
Subject: | Authentication_test.php |
<?php
// Version 1.0
// This is a sample PHP to implement an authentication web service
// our servers will call your web service to Accept or Reject connections
// If code is to provide a starting point for a developer wanting to create their own
// authentication rules for their streaming.
//
// If you modify this script or create a new one make sure you keep your SOAP messages compatible
// with the definitions inside Authentication.wsdl
//
// If you change the WSDL definitions or SOAP structure the client may not understand how to
// interact with your code
// Create a soap server object based off the standard WSDL provided.
$server = new soapserver("Auth.wsdl", array('encoding'=>'UTF-8'));
/* function: Authenticate
* Purpose: This is the method that will be called during each connection
* Use one of the input parameters as a criteria to authenticate the client
*
* Comments: Keep the duration between entering and exiting this function to a minimum
* The client cannot begin streaming until you send back a result
* If an extremely long time has lapsed the web service client may also terminate the
* connection
*
* Inputs:
* (strings)account The name of the account associated with this request
* This could be useful if you have multiple accounts, otherwise is will
* always contain the same value.
*
* (strings)token This is the unique string that was passed into the Player
* This can be a alpha numeric and should not be predictable
*
* (strings)referrer This is the referrer passed to the server, usually this is the url
* to the .swf
*
* (strings)sourceURL This is the full URL being requested from the server
*
* (strings)ip This is the IP of the client connecting to the server
*
* Output:
* (int)0 Reject Access
* (int)1 Accept Access
*/
function Authenticate($account, $token, $referrer, $sourceurl, $ip)
{
// A very simple demonstration of how you can accept/reject connection on specific criteria
// In this case if the token is an even number we will allow access, if the number is odd we reject
if($token % 2 == 0) {
$retval = "1";
} else {
$retval = "0";
}
return $retval; // return ACCEPT(1) or REJECT(0)
}
// map the SOAP operation to the appropriate PHP function above
$server->addFunction("Authenticate");
// This is just some extra code to show what web service function is available if you browse this PHP
if ($_SERVER["REQUEST_METHOD"] == "POST") // If this is a post from the web service client then handle soap
{
header("Content-Type: text/xml"); // The client calling this code expects XML content-type
$server->handle(); // process the soap
}
else // this is probably a browser querying what function is available in this php
{
echo "This SOAP server can handle following functions:<br> ";
$functions = $server->getFunctions();
foreach($functions as $func)
{
echo $func . "<br>";
}
}
?>