henkversteeg Posted March 11, 2010 Share Posted March 11, 2010 With the Nusoap library I've build a simple webservice for testing purpose. (see code client ansd server below the message) The problem is that the function 'testje' in the webservice is sometimes executed several times within one call by the client. Some more details: client.php calls the webservice, function 'testje'. In this function, the username and password is validated (query on mysql database). If the user is known, than an Ok result is given, else an error result. That works all fine. For debugging purpose, the webservice writes a short message into log.txt. The sleep(3) is in the code to simulate a busy server. Here is the problem: Sometimes the log.txt is just one rule, but sometimes 2 or more rules (that means that the function has been executed more times within one call). Then the log.txt is: WS RECIEVE: 2010-03-10 09:56:47 from: 194.109.6.97 q=SELECT * FROM WebserviceClients WHERE clientUser = 'test' AND clientPass = 'test' LIMIT 1 WS RECIEVE: 2010-03-10 09:56:53 from: 194.109.6.97 q=SELECT * FROM WebserviceClients WHERE clientUser = 'test' AND clientPass = 'test' LIMIT 1 Note: this is within 1 call from the webservice. Does someone have an explanation for this? I want to create a webservice for an ordering system, to push orders in the system, but I don't want to have double orders etc. Many thanks! Client: <?php ini_set('display_errors',1); error_reporting(E_ALL); // Pull in the NuSOAP code require_once('lib/nusoap.php'); // Create the client instance $client = new nusoap_client('http://eendomein.nl/test/server.php?wsdl', true); // Check for an error $err = $client->getError(); if ($err) { // Display the error echo '<p><b>Constructor error: ' . $err . '</b></p>'; // At this point, you know the call that follows will fail } $input = "<auth><user>test</user><pass>test</pass></auth>"; // Call the SOAP method $result = $client->call('testje', array('param' => $input)); // Check for a fault if ($client->fault) { echo '<p><b>Fault: '; print_r($result); echo '</b></p>'; } else { // Check for errors $err = $client->getError(); if ($err) { // Display the error echo '<p><b>Error: ' . $err . '</b></p>'; } else { // Display the result print_r($result); } } ?> Server: <?php // Pull in the NuSOAP code require_once('lib/nusoap.php'); // Create the server instance $server = new soap_server(); // Initialize WSDL support $server->configureWSDL('testserver', 'urn:testserver'); // Register the method to expose $server->register('testje', // method name array('param' => 'xsd:string'), // input parameters array('return' => 'xsd:string'), // output parameters 'urn:testserver', // namespace 'urn:testserver#testje', // soapaction 'rpc', // style 'encoded', // use 'Testfunctie' // documentation ); function testje($param){ include('xml.php'); $db = mysql_connect("localhost","gbnaam","***") or die ("Verbinding mislukt"); mysql_select_db("eendbase",$db); $handle = fopen('log.txt','a'); $data = XML_unserialize($param); $user = $data['auth']['user']; $pass = $data['auth']['pass']; $q = "SELECT * FROM WebserviceClients WHERE clientUser = '".addslashes($user)."' AND clientPass = '".addslashes($pass)."' LIMIT 1"; $result = mysql_query($q); $nr = mysql_num_rows($result); $logMsg = 'WS RECIEVE: '.date('Y-m-d H:i:s').' from: '.$_SERVER['REMOTE_ADDR'].' q='.$q; fwrite($handle, $logMsg); fclose($handle); sleep(3); if ($nr == 1){ return "OK"; } else { return "ACCES DENIED"; } } $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : ''; $server->service($HTTP_RAW_POST_DATA); ?> Link to comment https://forums.phpfreaks.com/topic/194879-nusoap-webservice-unstable/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.